Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Macros | Functions | Variables
fgetsany.c File Reference

Like fgets(), but allocates memory and returns pointer to memory block. More...

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

Go to the source code of this file.

Macros

#define MAXBUFF   80 /* Memory allocated in chunks of this size */
 

Functions

char * blFgetsany (FILE *fp)
 

Variables

int errno
 

Detailed Description

Like fgets(), but allocates memory and returns pointer to memory block.

Version
V1.1
Date
07.07.14
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.

The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.

The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.

Description:

blFgetsany() provides a routine like fgets() for reading strings from a file, but does not require you to impose a limit on the length of string which may be read. fgetsany() allocates memory to store a string of any length and returns a pointer to that allocated memory. After use, this memory must be freed by the calling routine.

Usage:

blFgetsany() returns NULL on end-of-file and if memory allocation failed. It uses the global `errno' variable to indicate a memory allocation failure (errno==ENOMEM).

Typical usage is as follows:

#include "bioplib/general.h"
{
char *ptr;
FILE *fp;
fp = fopen("test.txt","r");
while((ptr=blFgetsany(fp))!=NULL)
{
printf("%s",ptr);
free(ptr);
}
if(errno)
perror("SYSTEM ERROR");
}

Revision History:

Definition in file fgetsany.c.

Macro Definition Documentation

#define MAXBUFF   80 /* Memory allocated in chunks of this size */

Definition at line 109 of file fgetsany.c.

Function Documentation

char* blFgetsany ( FILE *  fp)
Parameters
[in]*fpFile pointer open for reading
Returns
Allocated string or NULL on EOF and no memory (errno==ENOMEM)

blFgetsany() provides a routine like fgets() for reading strings from a file, but does not require you to impose a limit on the length of string which may be read. blFgetsany() allocates memory to store a string of any length and returns a pointer to that allocated memory. After use, this memory must be freed by the calling routine.

blFgetsany() returns NULL on end-of-file and if memory allocation failed. It uses the global `errno' variable to indicate a memory allocation failure (errno==ENOMEM).

  • 11.09.95 Original By: ACRM
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 143 of file fgetsany.c.

Variable Documentation

int errno