summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-27 08:57:23 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-27 08:57:23 +0000
commit41748e27c65310c83968cbd2f99e9a61c4a43e81 (patch)
tree933bc5ca89adb9ea128a2fc69ef6bdf606b3c4bd
parent91dd45207d057db4fcc2ed116a3c053d6bfe7b12 (diff)
Do not let isatty mess up errno
-rw-r--r--libc/stdio/stdio.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index 9a7afbc85..0d4708d97 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -1953,9 +1953,11 @@ void _stdio_term(void)
void _stdio_init(void)
{
#ifdef __STDIO_BUFFERS
+ int old_errno = errno;
/* stdin and stdout uses line buffering when connected to a tty. */
_stdio_streams[0].modeflags ^= (1-isatty(0)) * __FLAG_LBF;
_stdio_streams[1].modeflags ^= (1-isatty(1)) * __FLAG_LBF;
+ __set_errno(old_errno);
#endif /* __STDIO_BUFFERS */
#ifndef __UCLIBC__
/* __stdio_term is automatically when exiting if stdio is used.
@@ -2404,10 +2406,16 @@ FILE *_stdio_fopen(const char * __restrict filename,
return NULL;
}
- stream->modeflags |=
#ifdef __STDIO_BUFFERS
- (isatty(stream->filedes) * __FLAG_LBF) |
-#endif /* __STDIO_BUFFERS */
+ {
+ /* Do not let isatty mess up errno */
+ int old_errno = errno;
+ stream->modeflags |= (isatty(stream->filedes) * __FLAG_LBF);
+ __set_errno(old_errno);
+ }
+#endif
+
+ stream->modeflags |=
#if (O_APPEND == __FLAG_APPEND) \
&& ((O_LARGEFILE == __FLAG_LARGEFILE) || (O_LARGEFILE == 0))
(open_mode & (O_APPEND|O_LARGEFILE)) | /* i386 linux and elks */