diff options
author | Jim Meyering <jim@meyering.net> | 2003-10-31 13:47:11 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-10-31 13:47:11 +0000 |
commit | 87e53abf5549e908e7ea12bfa6ae00cb6ca2f8d4 (patch) | |
tree | cb9675572e8077e63a50c3d923d2ae5578cbe8c7 /lib | |
parent | 2f7002a28fb1c7ff84d1acbe62e1aefc5a89a169 (diff) | |
download | coreutils-87e53abf5549e908e7ea12bfa6ae00cb6ca2f8d4.tar.xz |
Update from gnulib.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/linebuffer.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/linebuffer.c b/lib/linebuffer.c index 434d6d858..0d35fc0ce 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -35,9 +35,7 @@ void initbuffer (struct linebuffer *linebuffer) { - linebuffer->length = 0; - linebuffer->size = 200; - linebuffer->buffer = xmalloc (linebuffer->size); + memset (linebuffer, 0, sizeof *linebuffer); } /* Read an arbitrarily long line of text from STREAM into LINEBUFFER. @@ -73,9 +71,9 @@ readlinebuffer (struct linebuffer *linebuffer, FILE *stream) } if (p == end) { - linebuffer->size *= 2; - buffer = xrealloc (buffer, linebuffer->size); - p = p - linebuffer->buffer + buffer; + size_t oldsize = linebuffer->size; + buffer = x2realloc (buffer, &linebuffer->size); + p = buffer + oldsize; linebuffer->buffer = buffer; end = buffer + linebuffer->size; } @@ -87,11 +85,10 @@ readlinebuffer (struct linebuffer *linebuffer, FILE *stream) return linebuffer; } -/* Free linebuffer LINEBUFFER and its data, all allocated with malloc. */ +/* Free the buffer that was allocated for linebuffer LINEBUFFER. */ void freebuffer (struct linebuffer *linebuffer) { free (linebuffer->buffer); - free (linebuffer); } |