diff options
author | das <das@FreeBSD.org> | 2009-04-06 13:50:04 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2009-04-06 13:50:04 +0000 |
commit | fb819f095f929ce46d622b8dc0e53ea46e567847 (patch) | |
tree | 55b9d467c4c819ca6310500170877ae242edc70b /lib/libc | |
parent | 53892e266cca1404bd5eb8d36e56d0a00a649da7 (diff) | |
download | FreeBSD-src-fb819f095f929ce46d622b8dc0e53ea46e567847.zip FreeBSD-src-fb819f095f929ce46d622b8dc0e53ea46e567847.tar.gz |
Return -1 instead of 0 upon reaching EOF. This is somewhat ill-advised
because it means getdelim() returns -1 for both error and EOF, and
never returns 0. However, this is what the original GNU implementation
does, and POSIX inherited the bug.
Reported by: marcus@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/getdelim.c | 6 | ||||
-rw-r--r-- | lib/libc/stdio/getline.3 | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c index fb02889..7af154f 100644 --- a/lib/libc/stdio/getdelim.c +++ b/lib/libc/stdio/getdelim.c @@ -120,7 +120,6 @@ getdelim(char ** __restrict linep, size_t * __restrict linecapp, int delim, goto error; } - linelen = 0; if (*linecapp == 0) *linep = NULL; @@ -128,9 +127,12 @@ getdelim(char ** __restrict linep, size_t * __restrict linecapp, int delim, /* If fp is at EOF already, we just need space for the NUL. */ if (__sferror(fp) || expandtofit(linep, 1, linecapp)) goto error; - goto done; + FUNLOCKFILE(fp); + (*linep)[0] = '\0'; + return (-1); } + linelen = 0; while ((endp = memchr(fp->_p, delim, fp->_r)) == NULL) { if (sappend(linep, &linelen, linecapp, fp->_p, fp->_r)) goto error; diff --git a/lib/libc/stdio/getline.3 b/lib/libc/stdio/getline.3 index 096331a..0465f93 100644 --- a/lib/libc/stdio/getline.3 +++ b/lib/libc/stdio/getline.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 28, 2009 +.Dd March 29, 2009 .Dt GETLINE 3 .Os .Sh NAME @@ -79,7 +79,7 @@ and functions return the number of characters written, excluding the terminating .Dv NUL . -The value \-1 is returned if an error occurs. +The value \-1 is returned if an error occurs, or if end-of-file is reached. .Sh EXAMPLES The following code fragment reads lines from a file and writes them to standard output. |