X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flinebuffer.c;h=8374a8a880bd6ffa617347ec26fee181d4150d28;hb=9d2aa9f846f853bc2211d6939580efdad8f34bd8;hp=5266dc1189fa1d6fe3701cd9b5634edc6c93fbc4;hpb=92f1833affa37844e22d2ebe4ca4c6ba924377f4;p=gnulib.git diff --git a/lib/linebuffer.c b/lib/linebuffer.c index 5266dc118..8374a8a88 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -25,9 +25,8 @@ #include #include "linebuffer.h" #include "unlocked-io.h" +#include "xalloc.h" -char *xmalloc (); -char *xrealloc (); void free (); /* Initialize linebuffer LINEBUFFER for use. */ @@ -37,14 +36,16 @@ initbuffer (struct linebuffer *linebuffer) { linebuffer->length = 0; linebuffer->size = 200; - linebuffer->buffer = (char *) xmalloc (linebuffer->size); + linebuffer->buffer = xmalloc (linebuffer->size); } /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. Keep the newline; append a newline if it's the last line of a file that ends in a non-newline character. Do not null terminate. - Return LINEBUFFER, except at end of file return 0. */ - + Therefore the stream can contain NUL bytes, and the length + (including the newline) is returned in linebuffer->length. + Return NULL upon error, or when STREAM is empty. + Otherwise, return LINEBUFFER. */ struct linebuffer * readline (struct linebuffer *linebuffer, FILE *stream) { @@ -54,7 +55,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) char *end = buffer + linebuffer->size; /* Sentinel. */ if (feof (stream) || ferror (stream)) - return 0; + return NULL; do { @@ -62,7 +63,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) if (c == EOF) { if (p == buffer) - return 0; + return NULL; if (p[-1] == '\n') break; c = '\n'; @@ -70,7 +71,7 @@ readline (struct linebuffer *linebuffer, FILE *stream) if (p == end) { linebuffer->size *= 2; - buffer = (char *) xrealloc (buffer, linebuffer->size); + buffer = xrealloc (buffer, linebuffer->size); p = p - linebuffer->buffer + buffer; linebuffer->buffer = buffer; end = buffer + linebuffer->size;