]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
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 3b334c5aa067130c481723abcf92289a16c2d8f4..13376637150f5c2a494ebfe5b8613f9e10a43f76 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 d7833e9760ffff1d52c8ed1db228ce631f9819e5..ca0ee8f0216715f5d3dbfdcea052d7535be02806 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 ca02dbeb3405dd16d5608e7509161e56c36f3eef..4f62dcd910e7d2e90ef50b97b0b0c539c440815f 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 3ee61520f4e60e68a280f71435ee879a552a80e4..dedc922ccdd5160356de59daceda52c41aa39872 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 cfa4c30b7890f55734bacd54a4701348187b8ed9..753a5ac1500e028be38e9d7f1491704c4f5f37e2 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;                                                          \
        }                                                                     \