summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-08-03 18:28:10 +0000
committerpfg <pfg@FreeBSD.org>2014-08-03 18:28:10 +0000
commit5c8726d1b258dd69e1f906f463c2bcc65c1b64a5 (patch)
treefffeed563f0bdf924883b06dc4de075adb02c829 /lib/libc
parenteabfc5bd75e50f98ad4963ab269825213771c398 (diff)
downloadFreeBSD-src-5c8726d1b258dd69e1f906f463c2bcc65c1b64a5.zip
FreeBSD-src-5c8726d1b258dd69e1f906f463c2bcc65c1b64a5.tar.gz
MFC r268926, r268930, r268983:
Use a correct errno in freopen. Use EBADF instead of EINVAL when working around incorrect O_ACCMODE. Adjust errno on failed prepwrite. rewind: always clear error indicator as required by POSIX. Obtained from: Apple Inc. (Libc 997.90.3) Phabric: D442
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/freopen.c2
-rw-r--r--lib/libc/stdio/rewind.c5
-rw-r--r--lib/libc/stdio/vfprintf.c4
-rw-r--r--lib/libc/stdio/vfwprintf.c4
-rw-r--r--lib/libc/stdio/wbuf.c5
5 files changed, 13 insertions, 7 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index dc5508d..b3a07d9 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -96,7 +96,7 @@ freopen(const char * __restrict file, const char * __restrict mode,
(oflags & O_ACCMODE)) {
fclose(fp);
FUNLOCKFILE(fp);
- errno = EINVAL;
+ errno = EBADF;
return (NULL);
}
if (fp->_flags & __SWR)
diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c
index ff4c907..133e3f4 100644
--- a/lib/libc/stdio/rewind.c
+++ b/lib/libc/stdio/rewind.c
@@ -53,9 +53,8 @@ rewind(FILE *fp)
__sinit();
FLOCKFILE(fp);
- if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) {
- clearerr_unlocked(fp);
+ if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0)
errno = serrno;
- }
+ clearerr_unlocked(fp); /* POSIX: clear stdio error regardless */
FUNLOCKFILE(fp);
}
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index ea47d36..e54e8ac 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -455,8 +455,10 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
return (__xvprintf(fp, fmt0, ap));
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
convbuf = NULL;
fmt = (char *)fmt0;
diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c
index 4350c48..b75c504 100644
--- a/lib/libc/stdio/vfwprintf.c
+++ b/lib/libc/stdio/vfwprintf.c
@@ -531,8 +531,10 @@ __vfwprintf(FILE *fp, locale_t locale, const wchar_t *fmt0, va_list ap)
/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
convbuf = NULL;
fmt = (wchar_t *)fmt0;
diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c
index 3f697e2..5bc3c4d 100644
--- a/lib/libc/stdio/wbuf.c
+++ b/lib/libc/stdio/wbuf.c
@@ -36,6 +36,7 @@ static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <errno.h>
#include <stdio.h>
#include "local.h"
@@ -59,8 +60,10 @@ __swbuf(int c, FILE *fp)
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
- if (prepwrite(fp) != 0)
+ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
c = (unsigned char)c;
ORIENT(fp, -1);
OpenPOWER on IntegriCloud