summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ungetwc.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-09-22 05:59:00 +0000
committertjr <tjr@FreeBSD.org>2002-09-22 05:59:00 +0000
commit66942d16196a10965c08f1bdfdea67bba8134550 (patch)
tree76b047271cf56936a6775126e3139bfdd2df1cab /lib/libc/stdio/ungetwc.c
parente54737666a584849daea897dbaf548d7ea1b8233 (diff)
downloadFreeBSD-src-66942d16196a10965c08f1bdfdea67bba8134550.zip
FreeBSD-src-66942d16196a10965c08f1bdfdea67bba8134550.tar.gz
Add an unlocked version of ungetwc(), __ungetwc(), that __vfwscanf()
will need to use.
Diffstat (limited to 'lib/libc/stdio/ungetwc.c')
-rw-r--r--lib/libc/stdio/ungetwc.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c
index 7602718..5eeb8b1 100644
--- a/lib/libc/stdio/ungetwc.c
+++ b/lib/libc/stdio/ungetwc.c
@@ -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);
+}
+
+/*
+ * MT-safe version.
+ */
+wint_t
+ungetwc(wint_t wc, FILE *fp)
+{
+ wint_t r;
-error:
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+ r = __ungetwc(wc, fp);
FUNLOCKFILE(fp);
- return (WEOF);
+
+ return (r);
}
OpenPOWER on IntegriCloud