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
This commit is contained in:
parent
591506d322
commit
325d97d0d1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130230
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user