diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 1996-10-27 00:33:07 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 1996-10-27 00:33:07 +0000 |
commit | fd8db52963bb30e4f294952d985dfa0649cd3117 (patch) | |
tree | 5ca49c567a0a120100f1a97d2a6ac08127ad6cb2 /lib/libc | |
parent | 43d84cd39f18592ff97483d238a852c5b6c9634c (diff) |
Set errno to EBADF when attempting to write to a file pointer opened read-only
Diffstat (limited to 'lib/libc')
-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) && |