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