Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-06-14 07:56:05 +0400
committerEric Blake <eblake@redhat.com>2011-06-14 07:56:05 +0400
commit4226571d7af401f07fea4797b93c2c888f5e9880 (patch)
tree27ea4ca682438a63d1cbbe4a7656ad083e99a9a8 /newlib
parent0fdbb2d0cdf86dddcd7c915ab3ef1172c704ecc2 (diff)
printf: set errno for read-only stream
* 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.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog7
-rw-r--r--newlib/libc/stdio/fvwrite.c6
-rw-r--r--newlib/libc/stdio/local.h3
-rw-r--r--newlib/libc/stdio/wbuf.c6
-rw-r--r--newlib/libc/stdio/wsetup.c19
5 files changed, 26 insertions, 15 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index f2faad486..c01858381 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,10 @@
+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.
diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c
index d3878dc17..f196b3cfe 100644
--- a/newlib/libc/stdio/fvwrite.c
+++ b/newlib/libc/stdio/fvwrite.c
@@ -61,11 +61,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio),
/* make sure we can write */
if (cantwrite (ptr, fp))
- {
- fp->_flags |= __SERR;
- ptr->_errno = EBADF;
- return EOF;
- }
+ return EOF;
iov = uio->uio_iov;
len = 0;
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index 9ca948d96..187f7d858 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -113,7 +113,8 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *,
} \
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) && \
diff --git a/newlib/libc/stdio/wbuf.c b/newlib/libc/stdio/wbuf.c
index 33457f0d0..f9197ea9e 100644
--- a/newlib/libc/stdio/wbuf.c
+++ b/newlib/libc/stdio/wbuf.c
@@ -54,11 +54,7 @@ _DEFUN(__swbuf_r, (ptr, c, fp),
fp->_w = fp->_lbfsize;
if (cantwrite (ptr, fp))
- {
- fp->_flags |= __SERR;
- ptr->_errno = EBADF;
- return EOF;
- }
+ return EOF;
c = (unsigned char) c;
ORIENT (fp, -1);
diff --git a/newlib/libc/stdio/wsetup.c b/newlib/libc/stdio/wsetup.c
index dcbda0a35..08ae70f2c 100644
--- a/newlib/libc/stdio/wsetup.c
+++ b/newlib/libc/stdio/wsetup.c
@@ -20,12 +20,13 @@
#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
@@ -44,7 +45,11 @@ _DEFUN(__swsetup_r, (ptr, fp),
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 */
@@ -62,7 +67,7 @@ _DEFUN(__swsetup_r, (ptr, fp),
* 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);
@@ -79,5 +84,11 @@ _DEFUN(__swsetup_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;
}