From owner-svn-src-head@FreeBSD.ORG Mon Apr 6 13:50:05 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6F81D106567D; Mon, 6 Apr 2009 13:50:05 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 42A558FC15; Mon, 6 Apr 2009 13:50:05 +0000 (UTC) (envelope-from das@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n36Do5NR073150; Mon, 6 Apr 2009 13:50:05 GMT (envelope-from das@svn.freebsd.org) Received: (from das@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n36Do57l073147; Mon, 6 Apr 2009 13:50:05 GMT (envelope-from das@svn.freebsd.org) Message-Id: <200904061350.n36Do57l073147@svn.freebsd.org> From: David Schultz Date: Mon, 6 Apr 2009 13:50:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190773 - in head: lib/libc/stdio tools/regression/lib/libc/stdio X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2009 13:50:06 -0000 Author: das Date: Mon Apr 6 13:50:04 2009 New Revision: 190773 URL: http://svn.freebsd.org/changeset/base/190773 Log: 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@ Modified: head/lib/libc/stdio/getdelim.c head/lib/libc/stdio/getline.3 head/tools/regression/lib/libc/stdio/test-getdelim.c Modified: head/lib/libc/stdio/getdelim.c ============================================================================== --- head/lib/libc/stdio/getdelim.c Mon Apr 6 13:14:34 2009 (r190772) +++ head/lib/libc/stdio/getdelim.c Mon Apr 6 13:50:04 2009 (r190773) @@ -120,7 +120,6 @@ getdelim(char ** __restrict linep, size_ goto error; } - linelen = 0; if (*linecapp == 0) *linep = NULL; @@ -128,9 +127,12 @@ getdelim(char ** __restrict linep, size_ /* 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; Modified: head/lib/libc/stdio/getline.3 ============================================================================== --- head/lib/libc/stdio/getline.3 Mon Apr 6 13:14:34 2009 (r190772) +++ head/lib/libc/stdio/getline.3 Mon Apr 6 13:50:04 2009 (r190773) @@ -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. Modified: head/tools/regression/lib/libc/stdio/test-getdelim.c ============================================================================== --- head/tools/regression/lib/libc/stdio/test-getdelim.c Mon Apr 6 13:14:34 2009 (r190772) +++ head/tools/regression/lib/libc/stdio/test-getdelim.c Mon Apr 6 13:50:04 2009 (r190773) @@ -100,7 +100,7 @@ main(int argc, char *argv[]) assert(line[0] == '\0' && line[1] == '\0'); /* Third line: EOF */ line[0] = 'X'; - assert(getline(&line, &linecap, fp) == 0); + assert(getline(&line, &linecap, fp) == -1); assert(line[0] == '\0'); free(line); assert(feof(fp)); @@ -139,7 +139,7 @@ main(int argc, char *argv[]) free(line); line = NULL; linecap = 0; - assert(getline(&line, &linecap, fp) == 0); + assert(getline(&line, &linecap, fp) == -1); assert(line[0] == '\0'); assert(linecap > 0); assert(errno == 0);