summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/wsetup.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2004-06-08 05:44:52 +0000
committerdas <das@FreeBSD.org>2004-06-08 05:44:52 +0000
commit55edbf12e79020526adb2c4cd6d16638c3f7f15a (patch)
tree8d3a5c2c76db0241072041d4410c25b0d164ca4d /lib/libc/stdio/wsetup.c
parentf9a170c34a9a0d3656dea30832512c8f16ec97c8 (diff)
downloadFreeBSD-src-55edbf12e79020526adb2c4cd6d16638c3f7f15a.zip
FreeBSD-src-55edbf12e79020526adb2c4cd6d16638c3f7f15a.tar.gz
Set errno to EBADF on attempts to write to a stream that is not
writable. Affected callers include fwrite(), put?(), and *printf(). The issue of whether this is the right errno for funopened streams is unresolved, but that's an obscure case, and some errno is better than no errno. Discussed with: bde, jkh
Diffstat (limited to 'lib/libc/stdio/wsetup.c')
-rw-r--r--lib/libc/stdio/wsetup.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c
index 4039a11..4c18dd4 100644
--- a/lib/libc/stdio/wsetup.c
+++ b/lib/libc/stdio/wsetup.c
@@ -40,6 +40,7 @@ static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
@@ -47,7 +48,7 @@ __FBSDID("$FreeBSD$");
/*
* Various output routines call wsetup to be sure it is safe to write,
* because either _flags does not include __SWR, or _buf is NULL.
- * _wsetup returns 0 if OK to write, nonzero otherwise.
+ * _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno.
*/
int
__swsetup(fp)
@@ -61,8 +62,10 @@ __swsetup(fp)
* If we are not writing, we had better be reading and writing.
*/
if ((fp->_flags & __SWR) == 0) {
- if ((fp->_flags & __SRW) == 0)
+ if ((fp->_flags & __SRW) == 0) {
+ errno = EBADF;
return (EOF);
+ }
if (fp->_flags & __SRD) {
/* clobber any ungetc data */
if (HASUB(fp))
OpenPOWER on IntegriCloud