Adjust errno on failed prepwrite.

Obtained from:	Apple Inc. (Libc 997.90.3)
Phabric:	D442
MFC after:	1 week
This commit is contained in:
Pedro F. Giffuni 2014-07-20 21:24:29 +00:00
parent de65cb9aa9
commit 450ead8668
3 changed files with 10 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);