summaryrefslogtreecommitdiff
path: root/libc/stdio/_fopen.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-02-15 05:45:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-02-15 05:45:24 +0000
commit3c71e47750ea70d3dfa46490b28740eccf711956 (patch)
tree9ab93c745fb98ff2fa87bae1abcdb1e908ee04b4 /libc/stdio/_fopen.c
parent44d44d807ede85c53e05d88df82036b23c23e4a9 (diff)
suppress bogus ioctl on fd==INT_MAX when vasprintf() is called
Diffstat (limited to 'libc/stdio/_fopen.c')
-rw-r--r--libc/stdio/_fopen.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index fcbe1e4c6..51d1cf9bf 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -121,11 +121,11 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
i = (open_mode & (O_ACCMODE|O_LARGEFILE)) + 1;
/* NOTE: fopencookie needs changing if the basic check changes! */
- if (((i & (((int) fname_or_mode) + 1)) != i) /* Basic agreement? */
- || (((open_mode & ~((__mode_t) fname_or_mode)) & O_APPEND)
- && fcntl(filedes, F_SETFL, O_APPEND)) /* Need O_APPEND. */
- ) {
+ if ((i & ((int)fname_or_mode + 1)) != i) /* Basic agreement? */
goto DO_EINVAL;
+ if ((open_mode & ~(__mode_t)fname_or_mode) & O_APPEND) {
+ if (fcntl(filedes, F_SETFL, O_APPEND)) /* Need O_APPEND. */
+ goto DO_EINVAL;
}
/* For later... to reflect largefile setting in stream flags. */
__STDIO_WHEN_LFS( open_mode |= (((__mode_t) fname_or_mode)
@@ -159,9 +159,15 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
((((open_mode & O_ACCMODE) + 1) ^ 0x03) * __FLAG_WRITEONLY);
#ifdef __STDIO_BUFFERS
- i = errno; /* Preserve errno against isatty call. */
- stream->__modeflags |= (isatty(stream->__filedes) * __FLAG_LBF);
- __set_errno(i);
+ if (stream->__filedes != INT_MAX) {
+ /* NB: fopencookie uses bogus filedes == INT_MAX,
+ * avoiding isatty() in that case.
+ */
+ i = errno; /* preserve errno against isatty call. */
+ if (isatty(stream->__filedes))
+ stream->__modeflags |= __FLAG_LBF;
+ __set_errno(i);
+ }
if (!stream->__bufstart) {
if ((stream->__bufstart = malloc(BUFSIZ)) != NULL) {