Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdlib / mbstowcs_r.c
blob43aea2cdf627eeb1165f72a5a61b657f41d4919b
1 #include <stdlib.h>
2 #include <wchar.h>
3 #include "local.h"
5 size_t
6 _mbstowcs_r (struct _reent *r,
7 wchar_t *__restrict pwcs,
8 const char *__restrict s,
9 size_t n,
10 mbstate_t *state)
12 size_t ret = 0;
13 char *t = (char *)s;
14 int bytes;
16 if (!pwcs)
17 n = (size_t) 1; /* Value doesn't matter as long as it's not 0. */
18 while (n > 0)
20 bytes = __MBTOWC (r, pwcs, t, MB_CUR_MAX, state);
21 if (bytes < 0)
23 state->__count = 0;
24 return -1;
26 else if (bytes == 0)
27 break;
28 t += bytes;
29 ++ret;
30 if (pwcs)
32 ++pwcs;
33 --n;
36 return ret;