]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/mbsnrtowcs.c.patch
Libc-391.2.10.tar.gz
[apple/libc.git] / locale / FreeBSD / mbsnrtowcs.c.patch
1 --- mbsnrtowcs.c.orig Thu Nov 25 11:38:18 2004
2 +++ mbsnrtowcs.c Fri Feb 18 16:57:14 2005
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/mbsnrtowcs.c,v 1.1 2004/07/21 10:54:57 tjr Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <errno.h>
10 #include <limits.h>
11 #include <stdlib.h>
12 @@ -34,31 +36,40 @@
13 #include "mblocal.h"
14
15 size_t
16 -mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
17 - size_t nms, size_t len, mbstate_t * __restrict ps)
18 +mbsnrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src,
19 + size_t nms, 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 (__mbsnrtowcs(dst, src, nms, len, ps));
27 + ps = &loc->__mbs_mbsnrtowcs;
28 + return (loc->__lc_ctype->__mbsnrtowcs(dst, src, nms, len, ps, loc));
29 }
30
31 size_t
32 -__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
33 +mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
34 size_t nms, size_t len, mbstate_t * __restrict ps)
35 {
36 + return mbsnrtowcs_l(dst, src, nms, len, ps, __current_locale());
37 +}
38 +
39 +__private_extern__ size_t
40 +__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
41 + size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
42 +{
43 const char *s;
44 size_t nchr;
45 wchar_t wc;
46 size_t nb;
47 + size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
48 + size_t, mbstate_t * __restrict, locale_t)
49 + = loc->__lc_ctype->__mbrtowc;
50
51 s = *src;
52 nchr = 0;
53
54 if (dst == NULL) {
55 for (;;) {
56 - if ((nb = __mbrtowc(&wc, s, nms, ps)) == (size_t)-1)
57 + if ((nb = __mbrtowc(&wc, s, nms, ps, loc)) == (size_t)-1)
58 /* Invalid sequence - mbrtowc() sets errno. */
59 return ((size_t)-1);
60 else if (nb == 0 || nb == (size_t)-2)
61 @@ -71,7 +82,7 @@
62 }
63
64 while (len-- > 0) {
65 - if ((nb = __mbrtowc(dst, s, nms, ps)) == (size_t)-1) {
66 + if ((nb = __mbrtowc(dst, s, nms, ps, loc)) == (size_t)-1) {
67 *src = s;
68 return ((size_t)-1);
69 } else if (nb == (size_t)-2) {