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