summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fputwc.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-09-18 05:58:11 +0000
committertjr <tjr@FreeBSD.org>2002-09-18 05:58:11 +0000
commit5bb288ec923336fc582dae1b5ee61a4965037b5f (patch)
tree89b31678132bc76b873bf1bba095a04aa70ff775 /lib/libc/stdio/fputwc.c
parent2db6065cba040afe3448b330df0a30ed74c303da (diff)
downloadFreeBSD-src-5bb288ec923336fc582dae1b5ee61a4965037b5f.zip
FreeBSD-src-5bb288ec923336fc582dae1b5ee61a4965037b5f.tar.gz
Reimplement the functionality of fgetrune(), fputrune(), and fungetrune()
here in terms of mbrtowc(), wcrtomb(), and the single-byte I/O functions. The rune I/O functions are about to become deprecated in favour of the ones provided by ISO C90 Amd. 1 and C99.
Diffstat (limited to 'lib/libc/stdio/fputwc.c')
-rw-r--r--lib/libc/stdio/fputwc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c
index ae19cd6..c12581c 100644
--- a/lib/libc/stdio/fputwc.c
+++ b/lib/libc/stdio/fputwc.c
@@ -29,8 +29,8 @@ __FBSDID("$FreeBSD$");
#include "namespace.h"
#include <errno.h>
-#include <rune.h>
#include <stdio.h>
+#include <stdlib.h>
#include <wchar.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -39,8 +39,19 @@ __FBSDID("$FreeBSD$");
wint_t
fputwc(wchar_t wc, FILE *fp)
{
+ char buf[MB_LEN_MAX];
+ mbstate_t mbs;
+ size_t i, len;
ORIENTLOCK(fp, 1);
- return (fputrune((rune_t)wc, fp) != EOF ? (wint_t)wc : WEOF);
+ memset(&mbs, 0, sizeof(mbs));
+ if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
+ return (WEOF);
+
+ for (i = 0; i < len; i++)
+ if (fputc((unsigned char)buf[i], fp) == EOF)
+ return (WEOF);
+
+ return ((wint_t)wc);
}
OpenPOWER on IntegriCloud