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
This commit is contained in:
parent
eabfc5bd75
commit
5c8726d1b2
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user