X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flinebuffer.c;h=3f1e45b285b077ff617fac3a096d846e2fef654a;hb=8163bf0b83d43884567482189463bdb52642dffa;hp=434d6d8588638a921e4f5acf8fea1272065b388b;hpb=73bb09bd0106d33ceeb47a5a6ede8501272ea957;p=gnulib.git diff --git a/lib/linebuffer.c b/lib/linebuffer.c index 434d6d858..3f1e45b28 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -1,7 +1,7 @@ /* linebuffer.c -- read arbitrarily long lines - Copyright (C) 1986, 1991, 1998, 1999, 2001, 2003 Free Software - Foundation, Inc. + Copyright (C) 1986, 1991, 1998, 1999, 2001, 2003, 2004, 2006 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,29 +15,29 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Richard Stallman. */ - -#ifdef HAVE_CONFIG_H -# include -#endif + +#include #include #include +#include #include #include "linebuffer.h" -#include "unlocked-io.h" #include "xalloc.h" +#if USE_UNLOCKED_IO +# include "unlocked-io.h" +#endif + /* Initialize linebuffer LINEBUFFER for use. */ 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 +73,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 +87,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); }