]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- wcsnrtombs.c.orig 2004-11-25 11:38:20.000000000 -0800 |
2 | +++ wcsnrtombs.c 2005-02-18 18:38:25.000000000 -0800 | |
3 | @@ -27,6 +27,8 @@ | |
4 | #include <sys/cdefs.h> | |
5 | __FBSDID("$FreeBSD: src/lib/libc/locale/wcsnrtombs.c,v 1.2 2004/07/22 02:57:29 tjr 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 @@ | |
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 @@ | |
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 = (int)__wcrtomb(dst, *s, ps)) < 0) { | |
70 | + if ((nb = (int)__wcrtomb(dst, *s, ps, loc)) < 0) { | |
71 | *src = s; | |
72 | return ((size_t)-1); | |
73 | } | |
74 | @@ -86,7 +97,7 @@ | |
75 | * character is too long for the buffer. | |
76 | */ | |
77 | mbsbak = *ps; | |
78 | - if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) { | |
79 | + if ((nb = (int)__wcrtomb(buf, *s, ps, loc)) < 0) { | |
80 | *src = s; | |
81 | return ((size_t)-1); | |
82 | } |