1 | #include <reent.h> |
---|
2 | #include <newlib.h> |
---|
3 | #include <wchar.h> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <errno.h> |
---|
7 | #include <string.h> |
---|
8 | #include "local.h" |
---|
9 | |
---|
10 | size_t |
---|
11 | _mbrtowc_r (struct _reent *ptr, |
---|
12 | wchar_t *pwc, |
---|
13 | const char *s, |
---|
14 | size_t n, |
---|
15 | mbstate_t *ps) |
---|
16 | { |
---|
17 | int retval = 0; |
---|
18 | |
---|
19 | #ifdef _MB_CAPABLE |
---|
20 | if (ps == NULL) |
---|
21 | { |
---|
22 | _REENT_CHECK_MISC(ptr); |
---|
23 | ps = &(_REENT_MBRTOWC_STATE(ptr)); |
---|
24 | } |
---|
25 | #endif |
---|
26 | |
---|
27 | if (s == NULL) |
---|
28 | retval = __MBTOWC (ptr, NULL, "", 1, ps); |
---|
29 | else |
---|
30 | retval = __MBTOWC (ptr, pwc, s, n, 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 | mbrtowc (wchar_t *__restrict pwc, |
---|
45 | const char *__restrict s, |
---|
46 | size_t n, |
---|
47 | mbstate_t *__restrict ps) |
---|
48 | { |
---|
49 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) |
---|
50 | return _mbrtowc_r (_REENT, pwc, s, n, ps); |
---|
51 | #else |
---|
52 | int retval = 0; |
---|
53 | struct _reent *reent = _REENT; |
---|
54 | |
---|
55 | #ifdef _MB_CAPABLE |
---|
56 | if (ps == NULL) |
---|
57 | { |
---|
58 | _REENT_CHECK_MISC(reent); |
---|
59 | ps = &(_REENT_MBRTOWC_STATE(reent)); |
---|
60 | } |
---|
61 | #endif |
---|
62 | |
---|
63 | if (s == NULL) |
---|
64 | retval = __MBTOWC (reent, NULL, "", 1, ps); |
---|
65 | else |
---|
66 | retval = __MBTOWC (reent, pwc, s, n, 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 */ |
---|