1 /*
2 Copyright (c) 2002 Thomas Fitzsimmons <fitzsim@redhat.com>
3 */
4 #include <newlib.h>
5 #include <wchar.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <string.h>
10 #include "local.h"
11
12 #ifndef _REENT_ONLY
13 size_t
mbrtowc(wchar_t * __restrict pwc,const char * __restrict s,size_t n,mbstate_t * __restrict ps)14 mbrtowc (wchar_t *__restrict pwc,
15 const char *__restrict s,
16 size_t n,
17 mbstate_t *__restrict ps)
18 {
19 int retval = 0;
20
21 #ifdef _MB_CAPABLE
22 if (ps == NULL)
23 {
24 static NEWLIB_THREAD_LOCAL mbstate_t _mbrtowc_state;
25 ps = &_mbrtowc_state;
26 }
27 #endif
28
29 if (s == NULL)
30 retval = __MBTOWC (NULL, "", 1, ps);
31 else
32 retval = __MBTOWC (pwc, s, n, ps);
33
34 if (retval == -1)
35 {
36 ps->__count = 0;
37 _REENT_ERRNO(reent) = EILSEQ;
38 return (size_t)(-1);
39 }
40 else
41 return (size_t)retval;
42 }
43 #endif /* !_REENT_ONLY */
44