diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-20 13:20:41 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-20 13:20:41 +0000 |
commit | 8f030a44b8c665d111ed900df1a8203dde0af1e7 (patch) | |
tree | dba84dabdfa686ba4668a3256bd3ecb1eb4313be /lib/libc/stdio/fputwc.c | |
parent | f90c382c0c6c8b94d43903c8df4b52b4574fadd8 (diff) | |
download | src-8f030a44b8c665d111ed900df1a8203dde0af1e7.tar.gz src-8f030a44b8c665d111ed900df1a8203dde0af1e7.zip |
Introduce unlocked versions of fputwc() and fgetwc() called __fputwc()
and __fgetwc() which can be used when we know the file is locked.
Notes
Notes:
svn path=/head/; revision=103676
Diffstat (limited to 'lib/libc/stdio/fputwc.c')
-rw-r--r-- | lib/libc/stdio/fputwc.c | 32 |
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); } |