FGETFLN(3)

NAME
fgetfln - read an arbitrarily long, possibly continued line (DRAFT)

SYNOPSIS
#include <stdio.h>
#include <fgetfln.h>

char *fgetfln(stream, limit, lenp)
FILE *stream;
int limit, *lenp;

char *fgetln(stream)
FILE *stream;

char *cfgetln(stream)
FILE *stream;

char *fgetline(stream, lenp)
FILE *stream;
int *lenp;

char *dogets(line, lenp)
char *line;
int *lenp;

DESCRIPTION
Fgetfln reads an arbitrarily long line from stream, allocating memory via malloc(3) as needed. If limit is non-negative, fgetfln will read no more than limit bytes from stream. If lenp is non-null, strlen of the returned string will be stored through lenp.

fgetln (to read without continuations) and cfgetln (to read with continuations and remove leading whitespace) should be used instead when the limit is not needed. Their definitions are:

    #define fgetln(fp)  fgetfln(fp, -1, (int *)NULL)	/* unbounded read */
    #define cfgetln(fp) csfgetfln(fp, 1)	/* unbounded cont.d read */

fgetline is the 4.4BSD routine. Dogets hacks any newline off the end of line (as determined from the strlen *lenp), adjusts *lenp to match, and returns line.

Fgetfln is intended to provide a reliable mechanism for reading input containing lines of arbitrary length, rather than trusting that no line will be longer than some arbitrary tolerance.

The memory returned by fgetfln must not be returned via free(3); it will be reused by fgetfln. Conversely, the memory returned by csfgetln must be returned via free(3).

SEE ALSO
malloc(3), fgets(3)

DIAGNOSTICS
Returns NULL (0) if memory cannot be allocated or upon reading end-of-file; use feof(stream) to distinguish.

HISTORY
Written by Geoff Collyer at Software Tool & Die as part of the C news project.

BUGS
It's not yet clear how fast csfgetln is.