X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..aa54d2fad3d9038b43475aa93c76795c5141a993:/stdio/FreeBSD/fputwc.c diff --git a/stdio/FreeBSD/fputwc.c b/stdio/FreeBSD/fputwc.c index 55b02fa..e835bc2 100644 --- a/stdio/FreeBSD/fputwc.c +++ b/stdio/FreeBSD/fputwc.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +25,9 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.5 2002/10/16 12:09:43 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 @@ -36,18 +38,19 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.5 2002/10/16 12:09:43 tjr Ex #include "un-namespace.h" #include "libc_private.h" #include "local.h" +#include "mblocal.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]; - mbstate_t mbs; size_t i, len; + struct __xlocale_st_runelocale *xrl = loc->__lc_ctype; - if (MB_LEN_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 @@ -56,8 +59,7 @@ __fputwc(wchar_t wc, FILE *fp) *buf = (unsigned char)wc; len = 1; } else { - memset(&mbs, 0, sizeof(mbs)); - if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + if ((len = loc->__lc_ctype->__wcrtomb(buf, wc, &fp->_mbstate, loc)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); } @@ -80,7 +82,21 @@ fputwc(wchar_t wc, FILE *fp) 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);