]> git.saurik.com Git - apple/libc.git/blame - stdio/FreeBSD/fputwc.c.patch
Libc-583.tar.gz
[apple/libc.git] / stdio / FreeBSD / fputwc.c.patch
CommitLineData
3d9156a7
A
1--- fputwc.c.orig 2004-11-25 11:38:34.000000000 -0800
2+++ fputwc.c 2005-02-23 17:21:10.000000000 -0800
3@@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.10 2004/07/20 08:27:27 tjr Exp $");
6
7+#include "xlocale_private.h"
8+
9 #include "namespace.h"
10 #include <errno.h>
11 #include <limits.h>
12@@ -41,13 +43,14 @@
13 /*
14 * Non-MT-safe version.
15 */
16-wint_t
17-__fputwc(wchar_t wc, FILE *fp)
18+__private_extern__ wint_t
19+__fputwc(wchar_t wc, FILE *fp, locale_t loc)
20 {
21 char buf[MB_LEN_MAX];
22 size_t i, len;
23+ struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
24
25- if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
26+ if (xrl->__mb_cur_max == 1 && wc > 0 && wc <= UCHAR_MAX) {
27 /*
28 * Assume single-byte locale with no special encoding.
29 * A more careful test would be to check
30@@ -56,7 +59,7 @@
31 *buf = (unsigned char)wc;
32 len = 1;
33 } else {
34- if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) ==
35+ if ((len = xrl->__wcrtomb(buf, wc, &fp->_extra->mbstate, loc)) ==
36 (size_t)-1) {
37 fp->_flags |= __SERR;
38 return (WEOF);
39@@ -80,7 +83,21 @@
40
41 FLOCKFILE(fp);
42 ORIENT(fp, 1);
43- r = __fputwc(wc, fp);
44+ r = __fputwc(wc, fp, __current_locale());
45+ FUNLOCKFILE(fp);
46+
47+ return (r);
48+}
49+
50+wint_t
51+fputwc_l(wchar_t wc, FILE *fp, locale_t loc)
52+{
53+ wint_t r;
54+
55+ NORMALIZE_LOCALE(loc);
56+ FLOCKFILE(fp);
57+ ORIENT(fp, 1);
58+ r = __fputwc(wc, fp, loc);
59 FUNLOCKFILE(fp);
60
61 return (r);