]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/wcsnrtombs.c.patch
e4ba34b855e2de31554f734c657414de9e1e298b
[apple/libc.git] / locale / FreeBSD / wcsnrtombs.c.patch
1 --- wcsnrtombs.c.bsdnew 2009-11-09 15:05:25.000000000 -0800
2 +++ wcsnrtombs.c 2009-11-09 17:47:14.000000000 -0800
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/wcsnrtombs.c,v 1.3 2005/02/12 08:45:12 stefanf Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <limits.h>
10 #include <stdlib.h>
11 #include <string.h>
12 @@ -34,32 +36,41 @@ __FBSDID("$FreeBSD: src/lib/libc/locale/
13 #include "mblocal.h"
14
15 size_t
16 -wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
17 - size_t len, mbstate_t * __restrict ps)
18 +wcsnrtombs_l(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
19 + size_t len, mbstate_t * __restrict ps, locale_t loc)
20 {
21 - static mbstate_t mbs;
22 -
23 + NORMALIZE_LOCALE(loc);
24 if (ps == NULL)
25 - ps = &mbs;
26 - return (__wcsnrtombs(dst, src, nwc, len, ps));
27 + ps = &loc->__mbs_wcsnrtombs;
28 + return (loc->__lc_ctype->__wcsnrtombs(dst, src, nwc, len, ps, loc));
29 }
30
31 size_t
32 +wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
33 + size_t len, mbstate_t * __restrict ps)
34 +{
35 + return wcsnrtombs_l(dst, src, nwc, len, ps, __current_locale());
36 +}
37 +
38 +__private_extern__ size_t
39 __wcsnrtombs_std(char * __restrict dst, const wchar_t ** __restrict src,
40 - size_t nwc, size_t len, mbstate_t * __restrict ps)
41 + size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
42 {
43 mbstate_t mbsbak;
44 char buf[MB_LEN_MAX];
45 const wchar_t *s;
46 size_t nbytes;
47 size_t nb;
48 + struct __xlocale_st_runelocale *runeLocale = loc->__lc_ctype;
49 + size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t) = runeLocale->__wcrtomb;
50 + int mb_cur_max = runeLocale->__mb_cur_max;
51
52 s = *src;
53 nbytes = 0;
54
55 if (dst == NULL) {
56 while (nwc-- > 0) {
57 - if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1)
58 + if ((nb = __wcrtomb(buf, *s, ps, loc)) == (size_t)-1)
59 /* Invalid character - wcrtomb() sets errno. */
60 return ((size_t)-1);
61 else if (*s == L'\0')
62 @@ -71,9 +82,9 @@ __wcsnrtombs_std(char * __restrict dst,
63 }
64
65 while (len > 0 && nwc-- > 0) {
66 - if (len > (size_t)MB_CUR_MAX) {
67 + if (len > (size_t)mb_cur_max) {
68 /* Enough space to translate in-place. */
69 - if ((nb = __wcrtomb(dst, *s, ps)) == (size_t)-1) {
70 + if ((nb = __wcrtomb(dst, *s, ps, loc)) == (size_t)-1) {
71 *src = s;
72 return ((size_t)-1);
73 }
74 @@ -86,7 +97,7 @@ __wcsnrtombs_std(char * __restrict dst,
75 * character is too long for the buffer.
76 */
77 mbsbak = *ps;
78 - if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1) {
79 + if ((nb = __wcrtomb(buf, *s, ps, loc)) == (size_t)-1) {
80 *src = s;
81 return ((size_t)-1);
82 }