Add commentary explaining why we return EBADF upon attempts to fflush() a

read-only file.

Discussed on:	-current
This commit is contained in:
Colin Percival 2004-07-04 20:17:00 +00:00
parent decbf84ef3
commit 0a31135d11
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=131592

View File

@ -61,6 +61,18 @@ fflush(FILE *fp)
if (fp == NULL)
return (_fwalk(sflush_locked));
FLOCKFILE(fp);
/*
* There is disagreement about the correct behaviour of fflush()
* when passed a file which is not open for reading. According to
* the ISO C standard, the behaviour is undefined.
* Under linux, such an fflush returns success and has no effect;
* under Windows, such an fflush is documented as behaving instead
* as fpurge().
* Given that applications may be written with the expectation of
* either of these two behaviours, the only safe (non-astonishing)
* option is to return EBADF and ask that applications be fixed.
*/
if ((fp->_flags & (__SWR | __SRW)) == 0) {
errno = EBADF;
retval = EOF;