+2011-06-13 Eric Blake <eblake@redhat.com>
+
+ * libc/stdio/wsetup.c (__swsetup_r): Set errno on failure.
+ * libc/stdio/fvwrite.c (__sfvwrite_r): Simplify.
+ * libc/stdio/wbuf.c (__swbuf_r): Likewise.
+ * libc/stdio/local.h (cantwrite): Adjust comment.
+
2011-06-09 Yaakov Selkowitz <yselkowitz@...>
* libc/include/string.h (strdupa): New macro function.
} \
while (0)
-/* Return true iff the given FILE cannot be written now. */
+/* Return true and set errno and stream error flag iff the given FILE
+ cannot be written now. */
#define cantwrite(ptr, fp) \
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
#include <_ansi.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include "local.h"
/*
* 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, nonzero and set errno otherwise.
*/
int
if ((fp->_flags & __SWR) == 0)
{
if ((fp->_flags & __SRW) == 0)
- return EOF;
+ {
+ ptr->_errno = EBADF;
+ fp->_flags |= __SERR;
+ return EOF;
+ }
if (fp->_flags & __SRD)
{
/* clobber any ungetc data */
* A string I/O file should not explicitly allocate a buffer
* unless asprintf is being used.
*/
- if (fp->_bf._base == NULL
+ if (fp->_bf._base == NULL
&& (!(fp->_flags & __SSTR) || (fp->_flags & __SMBF)))
__smakebuf_r (ptr, fp);
else
fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
- return (!fp->_bf._base && (fp->_flags & __SMBF)) ? EOF : 0;
+ if (!fp->_bf._base && (fp->_flags & __SMBF))
+ {
+ /* __smakebuf_r set errno, but not flag */
+ fp->_flags |= __SERR;
+ return EOF;
+ }
+ return 0;
}