Set stream errors in more cases
authorUlrich Drepper <drepper@gmail.com>
Sat, 21 May 2011 04:42:06 +0000 (00:42 -0400)
committerUlrich Drepper <drepper@gmail.com>
Sat, 21 May 2011 04:42:06 +0000 (00:42 -0400)
Also avoid unnecessarily setting errno when testing for TTY.

ChangeLog
NEWS
libio/filedoalloc.c
stdio-common/perror.c
stdio-common/vfprintf.c

index 3b334c5..1337663 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-05-21  Ulrich Drepper  <drepper@gmail.com>
+
+       [BZ #12792]
+       * libio/filedoalloc.c (local_isatty): New function.
+       (_IO_file_doallocate): Use local_isatty.
+       * stdio-common/perror.c (perror): In case a new stream is used
+       forward the stream error.
+       * stdio-common/vfprintf.c (ARGCHECK): For read-only streams also set
+       error flag.
+
 2011-05-20  Ulrich Drepper  <drepper@gmail.com>
 
        [BZ #11869]
diff --git a/NEWS b/NEWS
index d7833e9..ca0ee8f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes.  2011-5-20
+GNU C Library NEWS -- history of user-visible changes.  2011-5-21
 Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
 See the end for copying conditions.
 
@@ -16,7 +16,7 @@ Version 2.14
   12454, 12460, 12469, 12489, 12509, 12510, 12511, 12518, 12527, 12541,
   12545, 12551, 12582, 12583, 12587, 12597, 12601, 12611, 12625, 12626,
   12631, 12650, 12653, 12655, 12660, 12681, 12685, 12711, 12713, 12714,
-  12717, 12723, 12724, 12734, 12738, 12746, 12766, 12775
+  12717, 12723, 12724, 12734, 12738, 12746, 12766, 12775, 12792
 
 * The RPC implementation in libc is obsoleted.  Old programs keep working
   but new programs cannot be linked with the routines in libc anymore.
index ca02dbe..4f62dcd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997, 2001, 2002, 2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -41,7 +41,7 @@
    4. Neither the name of the University nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 # include <device-nrs.h>
 #endif
 
+
+static int
+local_isatty (int fd)
+{
+  int save_errno = errno;
+  int res = isatty (fd);
+  __set_errno (save_errno);
+  return res;
+}
+
+
 /*
  * Allocate a file buffer, or switch to unbuffered I/O.
  * Per the ANSI C standard, ALL tty devices default to line buffered.
@@ -109,7 +120,7 @@ _IO_file_doallocate (fp)
 #ifdef DEV_TTY_P
              DEV_TTY_P (&st) ||
 #endif
-             isatty (fp->_fileno))
+             local_isatty (fp->_fileno))
            fp->_flags |= _IO_LINE_BUF;
        }
 #if _IO_HAVE_ST_BLKSIZE
index 3ee6152..dedc922 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-1993,1997,1998,2000-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1993,1997,1998,2000-2005,2011
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -73,6 +74,10 @@ perror (const char *s)
         position.  Since the stderr stream wasn't used so far we just
         write to the descriptor.  */
       perror_internal (fp, s, errnum);
+
+      if (_IO_ferror_unlocked (fp))
+       stderr->_flags |= _IO_ERR_SEEN;
+
       /* Close the stream.  */
       fclose (fp);
     }
index cfa4c30..753a5ac 100644 (file)
@@ -52,6 +52,7 @@
       CHECK_FILE (S, -1);                                                    \
       if (S->_flags & _IO_NO_WRITES)                                         \
        {                                                                     \
+         S->_flags |= _IO_ERR_SEEN;                                          \
          __set_errno (EBADF);                                                \
          return -1;                                                          \
        }                                                                     \