diff options
| author | christos <christos@NetBSD.org> | 2017-11-09 20:30:01 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2017-11-09 20:30:01 +0000 |
| commit | aaf64feec02754b6722a68fed65e472b450ba000 (patch) | |
| tree | f9eb3ff87e62ab81859ba0d5eb8d8e5a8787714f /lib/libc/stdio | |
| parent | f29b807ebe28ac7e7c33909b91d9d011ee1a938b (diff) | |
Add O_REGULAR to enforce opening of only regular files
(like we have O_DIRECTORY for directories).
This is better than open(, O_NONBLOCK), fstat()+S_ISREG() because opening
devices can have side effects.
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/fdopen.c | 6 | ||||
| -rw-r--r-- | lib/libc/stdio/flags.c | 6 | ||||
| -rw-r--r-- | lib/libc/stdio/fopen.c | 18 | ||||
| -rw-r--r-- | lib/libc/stdio/freopen.c | 19 |
4 files changed, 10 insertions, 39 deletions
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index 99a78d006e8..d1cbe628fcf 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: fdopen.c,v 1.17 2017/01/10 17:00:58 christos Exp $ */ +/* $NetBSD: fdopen.c,v 1.18 2017/11/09 20:30:02 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fdopen.c,v 1.17 2017/01/10 17:00:58 christos Exp $"); +__RCSID("$NetBSD: fdopen.c,v 1.18 2017/11/09 20:30:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -92,7 +92,7 @@ fdopen(int fd, const char *mode) return NULL; } - if (oflags & O_NONBLOCK) { + if (oflags & O_REGULAR) { struct stat st; if (fstat(fd, &st) == -1) { return NULL; diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index 6a13b1417d8..7486a33bafe 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -1,4 +1,4 @@ -/* $NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $ */ +/* $NetBSD: flags.c,v 1.19 2017/11/09 20:30:02 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: flags.c,v 1.18 2017/11/04 02:49:55 christos Exp $"); +__RCSID("$NetBSD: flags.c,v 1.19 2017/11/09 20:30:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -105,7 +105,7 @@ __sflags(const char *mode, int *optr) o |= O_CLOEXEC; break; case 'f': - o |= O_NONBLOCK; + o |= O_REGULAR; break; case 'l': o |= O_NOFOLLOW; diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index 96b2c0566b1..8e5327f7494 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $ */ +/* $NetBSD: fopen.c,v 1.17 2017/11/09 20:30:02 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $"); +__RCSID("$NetBSD: fopen.c,v 1.17 2017/11/09 20:30:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -66,20 +66,6 @@ fopen(const char *file, const char *mode) return NULL; if ((f = open(file, oflags, DEFFILEMODE)) < 0) goto release; - if (oflags & O_NONBLOCK) { - struct stat st; - if (fstat(f, &st) == -1) { - int sverrno = errno; - (void)close(f); - errno = sverrno; - goto release; - } - if (!S_ISREG(st.st_mode)) { - (void)close(f); - errno = EFTYPE; - goto release; - } - } /* * File descriptors are a full int, but _file is only a short. * If we get a valid file descriptor that is greater or equal to diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index f83f51aad9d..ac3d2fbbcc5 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: freopen.c,v 1.19 2012/03/27 15:05:42 christos Exp $ */ +/* $NetBSD: freopen.c,v 1.20 2017/11/09 20:30:02 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: freopen.c,v 1.19 2012/03/27 15:05:42 christos Exp $"); +__RCSID("$NetBSD: freopen.c,v 1.20 2017/11/09 20:30:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -141,21 +141,6 @@ freopen(const char *file, const char *mode, FILE *fp) return NULL; } - if (oflags & O_NONBLOCK) { - struct stat st; - if (fstat(f, &st) == -1) { - sverrno = errno; - (void)close(f); - errno = sverrno; - return NULL; - } - if (!S_ISREG(st.st_mode)) { - (void)close(f); - errno = EFTYPE; - return NULL; - } - } - /* * If reopening something that was open before on a real file, try * to maintain the descriptor. Various C library routines (perror) |
