repo.or.cz
/
newlib-cygwin.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git]
/
newlib
/
libc
/
stdlib
/
mbstowcs_r.c
blob
43aea2cdf627eeb1165f72a5a61b657f41d4919b
1
#include <stdlib.h>
2
#include <wchar.h>
3
#include
"local.h"
4
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
)
11
{
12
size_t
ret
=
0
;
13
char
*
t
= (
char
*)
s
;
14
int
bytes
;
15
16
if
(!
pwcs
)
17
n
= (
size_t
)
1
;
/* Value doesn't matter as long as it's not 0. */
18
while
(
n
>
0
)
19
{
20
bytes
=
__MBTOWC
(
r
,
pwcs
,
t
,
MB_CUR_MAX
,
state
);
21
if
(
bytes
<
0
)
22
{
23
state
->
__count
=
0
;
24
return
-
1
;
25
}
26
else if
(
bytes
==
0
)
27
break
;
28
t
+=
bytes
;
29
++
ret
;
30
if
(
pwcs
)
31
{
32
++
pwcs
;
33
--
n
;
34
}
35
}
36
return
ret
;
37
}