getln - read one line of data
#include "getln.h"
int
getln(&buf,&sa,&match,sep);
int
getln2(&buf,&sa,&cont,&clen,sep);
buffer
buf;
stralloc sa;
int match;
int sep;
char *cont;
unsigned int clen;
getln reads a line of characters, terminated by a sep character, from buf. It returns the line in sa and sets match to 1. If getln sees end-of-input before it sees sep, it returns the partial line in sa and sets match to 0.
getln2 reads a line of characters, terminated by a sep character from buf. The line is returned in two pieces. The first piece is stored in sa. The second piece is cont, a pointer to clen characters inside buf. The second piece must be copied somewhere else before sa is used again. If getln2 sees end-of-input before it sees sep, it sets clen to 0 and does not set cont. It puts the partial line into sa.
buf can be a pre-allocated buffer like buffer_0 reading from STDIN or any other explicitly generated buffer on a given file descriptor.
getln normally returns 0. If it runs out of memory, or encounters an error from sa, it returns -1, setting errno appropriately.
getln2 normally returns 0. If it runs out of memory, or encounters an error from sa, it returns -1, setting errno appropriately.
The getln and getln2 man page were taken from Bruce Guenther and originally published by Dan Bernstein for qmail-1.03.
stralloc(3), buffer(3).