diff options
author | 1996-10-27 00:33:06 +0000 | |
---|---|---|
committer | 1996-10-27 00:33:06 +0000 | |
commit | 451ad32032dc613f61e820e2cea4a83652f45375 (patch) | |
tree | c6748f168925aef6caec2e821ecb64e7ec6be3e6 /lib/libc/stdio | |
parent | -z can now list/extra compressed files too. Uses new gz_iszipped() function. (diff) | |
download | wireguard-openbsd-451ad32032dc613f61e820e2cea4a83652f45375.tar.xz wireguard-openbsd-451ad32032dc613f61e820e2cea4a83652f45375.zip |
Set errno to EBADF when attempting to write to a file pointer opened read-only
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index ca7a7311b03..4d742e93e38 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: vfprintf.c,v 1.3 1996/09/24 20:02:14 michaels Exp $"; +static char *rcsid = "$OpenBSD: vfprintf.c,v 1.4 1996/10/27 00:33:06 tholo Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -49,6 +49,7 @@ static char *rcsid = "$OpenBSD: vfprintf.c,v 1.3 1996/09/24 20:02:14 michaels Ex #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> #if __STDC__ #include <stdarg.h> @@ -297,8 +298,10 @@ vfprintf(fp, fmt0, ap) *((type*)(argtable[nextarg++])) : (nextarg++, va_arg(ap, type))) /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) + if (cantwrite(fp)) { + errno = EBADF; return (EOF); + } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && |