*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.10 2004/07/20 08:27:27 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.11 2008/04/17 22:17:53 jhb Exp $");
+
+#include "xlocale_private.h"
#include "namespace.h"
#include <errno.h>
/*
* Non-MT-safe version.
*/
-wint_t
-__fputwc(wchar_t wc, FILE *fp)
+__private_extern__ wint_t
+__fputwc(wchar_t wc, FILE *fp, locale_t loc)
{
char buf[MB_LEN_MAX];
size_t i, len;
+ struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
- if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
+ if (xrl->__mb_cur_max == 1 && wc > 0 && wc <= UCHAR_MAX) {
/*
* Assume single-byte locale with no special encoding.
* A more careful test would be to check
*buf = (unsigned char)wc;
len = 1;
} else {
- if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) ==
- (size_t)-1) {
+ if ((len = loc->__lc_ctype->__wcrtomb(buf, wc, &fp->_mbstate, loc)) == (size_t)-1) {
fp->_flags |= __SERR;
return (WEOF);
}
FLOCKFILE(fp);
ORIENT(fp, 1);
- r = __fputwc(wc, fp);
+ r = __fputwc(wc, fp, __current_locale());
+ FUNLOCKFILE(fp);
+
+ return (r);
+}
+
+wint_t
+fputwc_l(wchar_t wc, FILE *fp, locale_t loc)
+{
+ wint_t r;
+
+ NORMALIZE_LOCALE(loc);
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+ r = __fputwc(wc, fp, loc);
FUNLOCKFILE(fp);
return (r);