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