summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2001-03-17 19:05:51 +0000
committerManuel Novoa III <mjn3@codepoet.org>2001-03-17 19:05:51 +0000
commita91d0a538d52c77fd56a3f44974f96654125d9db (patch)
treed8778f4311c38e210f1b0a93f3b35763016e6037 /libc
parent162b5c1c0a1d12b47250e422b036882eefc99732 (diff)
Fix fdopen mode-compatibility test and errno setting.
Diffstat (limited to 'libc')
-rw-r--r--libc/stdio/stdio.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index 73b9d1aee..fe1c6a073 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -701,8 +701,15 @@ const char *mode;
if (fname) { /* Open the file itself */
fd = open(fname, open_mode, 0666);
} else { /* fdopen -- check mode is compatible. */
+#if O_ACCMODE != 3 || O_RDONLY != 0 || O_WRONLY != 1 || O_RDWR != 2
+#error Assumption violated - mode constants
+#endif
cur_mode = fcntl(fd, F_GETFL);
- if ((cur_mode == -1) || ((cur_mode ^ open_mode) & O_ACCMODE)) {
+ if (cur_mode == -1) {
+ fd = -1;
+ } else if (!(cur_mode & O_RDWR)
+ && ((cur_mode ^ open_mode) & O_ACCMODE)) {
+ errno = EINVAL;
fd = -1;
}
}