aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdio/fputwc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/fputwc.c')
-rw-r--r--lib/libc/stdio/fputwc.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c
index 34751ddbfb8d..10c3c18a5c45 100644
--- a/lib/libc/stdio/fputwc.c
+++ b/lib/libc/stdio/fputwc.c
@@ -37,16 +37,16 @@ __FBSDID("$FreeBSD$");
#include "libc_private.h"
#include "local.h"
+/*
+ * Non-MT-safe version.
+ */
wint_t
-fputwc(wchar_t wc, FILE *fp)
+__fputwc(wchar_t wc, FILE *fp)
{
char buf[MB_LEN_MAX];
mbstate_t mbs;
size_t i, len;
- FLOCKFILE(fp);
- ORIENT(fp, 1);
-
if (MB_LEN_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
/*
* Assume single-byte locale with no special encoding.
@@ -57,19 +57,29 @@ fputwc(wchar_t wc, FILE *fp)
len = 1;
} else {
memset(&mbs, 0, sizeof(mbs));
- if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
- FUNLOCKFILE(fp);
+ if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
return (WEOF);
- }
}
for (i = 0; i < len; i++)
- if (__sputc((unsigned char)buf[i], fp) == EOF) {
- FUNLOCKFILE(fp);
+ if (__sputc((unsigned char)buf[i], fp) == EOF)
return (WEOF);
- }
+ return ((wint_t)wc);
+}
+
+/*
+ * MT-safe version.
+ */
+wint_t
+fputwc(wchar_t wc, FILE *fp)
+{
+ wint_t r;
+
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+ r = __fputwc(wc, fp);
FUNLOCKFILE(fp);
- return ((wint_t)wc);
+ return (r);
}