From aec84f53952315ac1bd91036e37113d9cb3a303b Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 21 May 2011 00:42:06 -0400 Subject: Set stream errors in more cases Also avoid unnecessarily setting errno when testing for TTY. --- libio/filedoalloc.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'libio') diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c index ca02dbe..4f62dcd 100644 --- a/libio/filedoalloc.c +++ b/libio/filedoalloc.c @@ -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 @@ -74,6 +74,17 @@ # include #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 -- cgit v1.1