Add an unlocked version of ungetwc(), __ungetwc(), that __vfwscanf()

will need to use.
This commit is contained in:
Tim J. Robbins 2002-09-22 05:59:00 +00:00
parent e3b6e33c07
commit 5f147b57ac
2 changed files with 24 additions and 11 deletions

View File

@ -71,6 +71,7 @@ extern int _fwalk(int (*)(FILE *));
extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __ungetc(int, FILE *);
extern wint_t __ungetwc(wchar_t, FILE *);
extern int __vfprintf(FILE *, const char *, __va_list);
extern int __vfwprintf(FILE *, const wchar_t *, __va_list);

View File

@ -36,28 +36,40 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
#include "local.h"
/*
* Non-MT-safe version.
*/
wint_t
ungetwc(wint_t wc, FILE *fp)
__ungetwc(wint_t wc, FILE *fp)
{
char buf[MB_LEN_MAX];
mbstate_t mbs;
size_t len;
FLOCKFILE(fp);
ORIENT(fp, 1);
if (wc == WEOF)
goto error;
return (WEOF);
memset(&mbs, 0, sizeof(mbs));
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
goto error;
return (WEOF);
while (len-- != 0)
if (__ungetc((unsigned char)buf[len], fp) == EOF)
goto error;
FUNLOCKFILE(fp);
return (WEOF);
return (wc);
error:
FUNLOCKFILE(fp);
return (WEOF);
}
/*
* MT-safe version.
*/
wint_t
ungetwc(wint_t wc, FILE *fp)
{
wint_t r;
FLOCKFILE(fp);
ORIENT(fp, 1);
r = __ungetwc(wc, fp);
FUNLOCKFILE(fp);
return (r);
}