From 14ba5e14d9226cb4dd1b2a72781ee02e9f2bf8a2 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 15 Mar 2007 18:40:48 +0000 Subject: 2007-03-15 Eric Blake * libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant. (__smakebuf): Rename... (__smakebuf_r): to this. * libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup. * libc/stdio/makebuf.c (__smakebuf): Detect failed asprint allocation, then rename... (__smakebuf_r): ...to this and fix reentrancy. * libc/stdio/wsetup.c (__swsetup): Detect failed asprintf allocation, then rename... (__swsetup_r): ...to this and fix reentrancy. * libc/stdio/fseek.c (_fseek_r): Fix reentrancy. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/fclose.c (_fclose_r): Likewise. * libc/stdio/fread.c (_fread_r): Likewise. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/wbuf.c (__swbuf_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on failed asprintf allocation, and fix reentrancy. * libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow, as required by POSIX. * libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise. * libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise. * libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise. --- newlib/libc/stdio/fvwrite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'newlib/libc/stdio/fvwrite.c') diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c index 21167c7f1..0d91aa2d9 100644 --- a/newlib/libc/stdio/fvwrite.c +++ b/newlib/libc/stdio/fvwrite.c @@ -60,7 +60,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), return 0; /* make sure we can write */ - if (cantwrite (fp)) + if (cantwrite (ptr, fp)) { fp->_flags |= __SERR; ptr->_errno = EBADF; @@ -147,6 +147,8 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), { /* Free buffer which is no longer used. */ _free_r (ptr, fp->_bf._base); + /* Ensure correct errno, even if free changed it. */ + ptr->_errno = ENOMEM; goto err; } fp->_bf._base = str; -- cgit v1.2.3