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 <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <errno.h>
 #include <stdio.h>
 #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);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to