2000-02-18 03:39:52 +08:00
|
|
|
#include <stdlib.h>
|
2002-08-23 09:56:05 +08:00
|
|
|
#include <wchar.h>
|
2009-11-18 17:49:57 +08:00
|
|
|
#include "local.h"
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
size_t
|
2017-12-04 11:43:30 +08:00
|
|
|
_mbstowcs_r (struct _reent *r,
|
2017-12-04 09:31:41 +08:00
|
|
|
wchar_t *__restrict pwcs,
|
|
|
|
const char *__restrict s,
|
|
|
|
size_t n,
|
2002-08-23 09:56:05 +08:00
|
|
|
mbstate_t *state)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
2009-03-17 20:16:28 +08:00
|
|
|
size_t ret = 0;
|
2000-02-18 03:39:52 +08:00
|
|
|
char *t = (char *)s;
|
|
|
|
int bytes;
|
|
|
|
|
2009-03-17 20:16:28 +08:00
|
|
|
if (!pwcs)
|
|
|
|
n = (size_t) 1; /* Value doesn't matter as long as it's not 0. */
|
2000-02-18 03:39:52 +08:00
|
|
|
while (n > 0)
|
|
|
|
{
|
2016-07-21 04:05:59 +08:00
|
|
|
bytes = __MBTOWC (r, pwcs, t, MB_CUR_MAX, state);
|
2002-08-23 09:56:05 +08:00
|
|
|
if (bytes < 0)
|
2002-09-10 05:42:14 +08:00
|
|
|
{
|
|
|
|
state->__count = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
else if (bytes == 0)
|
2009-03-17 20:16:28 +08:00
|
|
|
break;
|
2000-02-18 03:39:52 +08:00
|
|
|
t += bytes;
|
2009-03-17 20:16:28 +08:00
|
|
|
++ret;
|
|
|
|
if (pwcs)
|
|
|
|
{
|
|
|
|
++pwcs;
|
|
|
|
--n;
|
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
2009-03-17 20:16:28 +08:00
|
|
|
return ret;
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|