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
/
string
/
strndup_r.c
blob
1b6cf84e583764836aeeeae3eff9573c098d3ca1
1
#include <reent.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
char
*
6
_strndup_r
(
struct
_reent
*
reent_ptr
,
7
const char
*
str
,
8
size_t
n
)
9
{
10
const char
*
ptr
=
str
;
11
size_t
len
;
12
char
*
copy
;
13
14
while
(
n
-- >
0
&& *
ptr
)
15
ptr
++;
16
17
len
=
ptr
-
str
;
18
19
copy
=
_malloc_r
(
reent_ptr
,
len
+
1
);
20
if
(
copy
)
21
{
22
memcpy
(
copy
,
str
,
len
);
23
copy
[
len
] =
'\0'
;
24
}
25
return
copy
;
26
}