Rev 4874 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include |
6 | #include |
7 | #include "local.h" |
7 | #include "local.h" |
8 | 8 | ||
9 | size_t |
9 | size_t |
10 | _DEFUN (_wcrtomb_r, (ptr, s, wc, ps), |
10 | _DEFUN (_wcrtomb_r, (ptr, s, wc, ps), |
11 | struct _reent *ptr _AND |
11 | struct _reent *ptr _AND |
12 | char *s _AND |
12 | char *s _AND |
13 | wchar_t wc _AND |
13 | wchar_t wc _AND |
14 | mbstate_t *ps) |
14 | mbstate_t *ps) |
15 | { |
15 | { |
16 | int retval = 0; |
16 | int retval = 0; |
17 | char buf[10]; |
17 | char buf[10]; |
18 | 18 | ||
19 | #ifdef _MB_CAPABLE |
19 | #ifdef _MB_CAPABLE |
20 | if (ps == NULL) |
20 | if (ps == NULL) |
21 | { |
21 | { |
22 | _REENT_CHECK_MISC(ptr); |
22 | _REENT_CHECK_MISC(ptr); |
23 | ps = &(_REENT_WCRTOMB_STATE(ptr)); |
23 | ps = &(_REENT_WCRTOMB_STATE(ptr)); |
24 | } |
24 | } |
25 | #endif |
25 | #endif |
26 | 26 | ||
27 | if (s == NULL) |
27 | if (s == NULL) |
28 | retval = __wctomb (ptr, buf, L'\0', __locale_charset (), ps); |
28 | retval = __wctomb (ptr, buf, L'\0', __locale_charset (), ps); |
29 | else |
29 | else |
30 | retval = __wctomb (ptr, s, wc, __locale_charset (), ps); |
30 | retval = __wctomb (ptr, s, wc, __locale_charset (), ps); |
31 | 31 | ||
32 | if (retval == -1) |
32 | if (retval == -1) |
33 | { |
33 | { |
34 | ps->__count = 0; |
34 | ps->__count = 0; |
35 | ptr->_errno = EILSEQ; |
35 | ptr->_errno = EILSEQ; |
36 | return (size_t)(-1); |
36 | return (size_t)(-1); |
37 | } |
37 | } |
38 | else |
38 | else |
39 | return (size_t)retval; |
39 | return (size_t)retval; |
40 | } |
40 | } |
41 | 41 | ||
42 | #ifndef _REENT_ONLY |
42 | #ifndef _REENT_ONLY |
43 | size_t |
43 | size_t |
44 | _DEFUN (wcrtomb, (s, wc, ps), |
44 | _DEFUN (wcrtomb, (s, wc, ps), |
45 | char *s _AND |
45 | char *__restrict s _AND |
46 | wchar_t wc _AND |
46 | wchar_t wc _AND |
47 | mbstate_t *ps) |
47 | mbstate_t *__restrict ps) |
48 | { |
48 | { |
49 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) |
49 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) |
50 | return _wcrtomb_r (_REENT, s, wc, ps); |
50 | return _wcrtomb_r (_REENT, s, wc, ps); |
51 | #else |
51 | #else |
52 | int retval = 0; |
52 | int retval = 0; |
- | 53 | struct _reent *reent = _REENT; |
|
53 | char buf[10]; |
54 | char buf[10]; |
54 | 55 | ||
55 | #ifdef _MB_CAPABLE |
56 | #ifdef _MB_CAPABLE |
56 | if (ps == NULL) |
57 | if (ps == NULL) |
57 | { |
58 | { |
58 | _REENT_CHECK_MISC(_REENT); |
59 | _REENT_CHECK_MISC(reent); |
59 | ps = &(_REENT_WCRTOMB_STATE(_REENT)); |
60 | ps = &(_REENT_WCRTOMB_STATE(reent)); |
60 | } |
61 | } |
61 | #endif |
62 | #endif |
62 | 63 | ||
63 | if (s == NULL) |
64 | if (s == NULL) |
64 | retval = __wctomb (_REENT, buf, L'\0', __locale_charset (), ps); |
65 | retval = __wctomb (reent, buf, L'\0', __locale_charset (), ps); |
65 | else |
66 | else |
66 | retval = __wctomb (_REENT, s, wc, __locale_charset (), ps); |
67 | retval = __wctomb (reent, s, wc, __locale_charset (), ps); |
67 | 68 | ||
68 | if (retval == -1) |
69 | if (retval == -1) |
69 | { |
70 | { |
70 | ps->__count = 0; |
71 | ps->__count = 0; |
71 | _REENT->_errno = EILSEQ; |
72 | reent->_errno = EILSEQ; |
72 | return (size_t)(-1); |
73 | return (size_t)(-1); |
73 | } |
74 | } |
74 | else |
75 | else |
75 | return (size_t)retval; |
76 | return (size_t)retval; |
76 | #endif /* not PREFER_SIZE_OVER_SPEED */ |
77 | #endif /* not PREFER_SIZE_OVER_SPEED */ |
77 | } |
78 | } |
78 | #endif /* !_REENT_ONLY */ |
79 | #endif /* !_REENT_ONLY */ |