From owner-svn-src-all@FreeBSD.ORG Sun Aug 3 18:28:11 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8A33050D for ; Sun, 3 Aug 2014 18:28:11 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6A13D2F2E for ; Sun, 3 Aug 2014 18:28:11 +0000 (UTC) Received: from pfg (uid 1275) (envelope-from pfg@FreeBSD.org) id 5c65 by svn.freebsd.org (DragonFly Mail Agent v0.9+); Sun, 03 Aug 2014 18:28:10 +0000 From: Pedro F. Giffuni Date: Sun, 3 Aug 2014 18:28:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r269482 - stable/10/lib/libc/stdio X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <53de7f3b.5c65.22d1a139@svn.freebsd.org> X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Aug 2014 18:28:11 -0000 Author: pfg Date: Sun Aug 3 18:28:10 2014 New Revision: 269482 URL: http://svnweb.freebsd.org/changeset/base/269482 Log: MFC r268926, r268930, r268983: Use a correct errno in freopen. Use EBADF instead of EINVAL when working around incorrect O_ACCMODE. Adjust errno on failed prepwrite. rewind: always clear error indicator as required by POSIX. Obtained from: Apple Inc. (Libc 997.90.3) Phabric: D442 Modified: stable/10/lib/libc/stdio/freopen.c stable/10/lib/libc/stdio/rewind.c stable/10/lib/libc/stdio/vfprintf.c stable/10/lib/libc/stdio/vfwprintf.c stable/10/lib/libc/stdio/wbuf.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdio/freopen.c ============================================================================== --- stable/10/lib/libc/stdio/freopen.c Sun Aug 3 18:12:55 2014 (r269481) +++ stable/10/lib/libc/stdio/freopen.c Sun Aug 3 18:28:10 2014 (r269482) @@ -96,7 +96,7 @@ freopen(const char * __restrict file, co (oflags & O_ACCMODE)) { fclose(fp); FUNLOCKFILE(fp); - errno = EINVAL; + errno = EBADF; return (NULL); } if (fp->_flags & __SWR) Modified: stable/10/lib/libc/stdio/rewind.c ============================================================================== --- stable/10/lib/libc/stdio/rewind.c Sun Aug 3 18:12:55 2014 (r269481) +++ stable/10/lib/libc/stdio/rewind.c Sun Aug 3 18:28:10 2014 (r269482) @@ -53,9 +53,8 @@ rewind(FILE *fp) __sinit(); FLOCKFILE(fp); - if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) { - clearerr_unlocked(fp); + if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) errno = serrno; - } + clearerr_unlocked(fp); /* POSIX: clear stdio error regardless */ FUNLOCKFILE(fp); } Modified: stable/10/lib/libc/stdio/vfprintf.c ============================================================================== --- stable/10/lib/libc/stdio/vfprintf.c Sun Aug 3 18:12:55 2014 (r269481) +++ stable/10/lib/libc/stdio/vfprintf.c Sun Aug 3 18:28:10 2014 (r269482) @@ -455,8 +455,10 @@ __vfprintf(FILE *fp, locale_t locale, co return (__xvprintf(fp, fmt0, ap)); /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (prepwrite(fp) != 0) + if (prepwrite(fp) != 0) { + errno = EBADF; return (EOF); + } convbuf = NULL; fmt = (char *)fmt0; Modified: stable/10/lib/libc/stdio/vfwprintf.c ============================================================================== --- stable/10/lib/libc/stdio/vfwprintf.c Sun Aug 3 18:12:55 2014 (r269481) +++ stable/10/lib/libc/stdio/vfwprintf.c Sun Aug 3 18:28:10 2014 (r269482) @@ -531,8 +531,10 @@ __vfwprintf(FILE *fp, locale_t locale, c /* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */ - if (prepwrite(fp) != 0) + if (prepwrite(fp) != 0) { + errno = EBADF; return (EOF); + } convbuf = NULL; fmt = (wchar_t *)fmt0; Modified: stable/10/lib/libc/stdio/wbuf.c ============================================================================== --- stable/10/lib/libc/stdio/wbuf.c Sun Aug 3 18:12:55 2014 (r269481) +++ stable/10/lib/libc/stdio/wbuf.c Sun Aug 3 18:28:10 2014 (r269482) @@ -36,6 +36,7 @@ static char sccsid[] = "@(#)wbuf.c 8.1 ( #include __FBSDID("$FreeBSD$"); +#include #include #include "local.h" @@ -59,8 +60,10 @@ __swbuf(int c, FILE *fp) * calls might wrap _w from negative to positive. */ fp->_w = fp->_lbfsize; - if (prepwrite(fp) != 0) + if (prepwrite(fp) != 0) { + errno = EBADF; return (EOF); + } c = (unsigned char)c; ORIENT(fp, -1);