Mercurial > hg > octave-nkf > gnulib-hg
changeset 1868:465f010d9cf2
(readline): Leave room for an extra byte
after the newline; comm needs this for memcoll.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sun, 04 Jul 1999 10:31:01 +0000 |
parents | 8cac4427bbda |
children | 0f0905dd78b2 |
files | lib/linebuffer.c |
diffstat | 1 files changed, 4 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -40,7 +40,8 @@ /* 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. + that ends in a non-newline character. Do not null terminate, + but leave room for an extra byte after the newline. Return LINEBUFFER, except at end of file return 0. */ struct linebuffer * @@ -49,7 +50,7 @@ int c; char *buffer = linebuffer->buffer; char *p = linebuffer->buffer; - char *end = buffer + linebuffer->size; /* Sentinel. */ + char *end = buffer + linebuffer->size - 1; /* Sentinel. */ if (feof (stream) || ferror (stream)) return 0; @@ -71,7 +72,7 @@ buffer = (char *) xrealloc (buffer, linebuffer->size); p = p - linebuffer->buffer + buffer; linebuffer->buffer = buffer; - end = buffer + linebuffer->size; + end = buffer + linebuffer->size - 1; } *p++ = c; }