|
NAMEgetdelim , getline —
get a line from a stream
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <stdio.h>
ssize_t
ssize_t
DESCRIPTIONThegetdelim () function reads a line from
stream, delimited by the character
delimiter. The getline ()
function is equivalent to getdelim () with the newline
character as the delimiter. The delimiter character is included as part of the
line, unless the end of the file is reached.
The caller may provide a pointer to a malloced buffer for the line
in *linep, and the capacity of that buffer in
*linecapp. These functions expand the buffer as
needed, as if via RETURN VALUESThegetdelim () and getline ()
functions return the number of characters stored in the buffer, excluding the
terminating NUL character. The value -1 is returned if
an error occurs, or if end-of-file is reached.
EXAMPLESThe following code fragment reads lines from a file and writes them to standard output. Thefwrite () function is used in case the line
contains embedded NUL characters.
char *line = NULL; size_t linecap = 0; ssize_t linelen; while ((linelen = getline(&line, &linecap, fp)) > 0) fwrite(line, linelen, 1, stdout); free(line); ERRORSThese functions may fail if:
These functions may also fail due to any of the errors specified
for SEE ALSOfgetln(3), fgets(3), malloc(3)STANDARDSThegetdelim () and getline ()
functions conform to IEEE Std 1003.1-2008
(“POSIX.1”).
HISTORYThese routines first appeared in FreeBSD 8.0.BUGSThere are no wide character versions ofgetdelim () or
getline ().
Visit the GSP FreeBSD Man Page Interface. |