summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ungetwc.c
diff options
context:
space:
mode:
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