Sign in
mojo
/
mojo-tools
/
b3a28bec1abb6642ddf21b21406c6666fb821438
/
.
/
fusl
/
src
/
string
/
strndup.c
blob: 31c3467ae6a68db5097896a823d188302d74e9d9 [
file
] [
log
] [
blame
]
#include
<stdlib.h>
#include
<string.h>
char
*
strndup
(
const
char
*
s
,
size_t
n
)
{
size_t
l
=
strnlen
(
s
,
n
);
char
*
d
=
malloc
(
l
+
1
);
if
(!
d
)
return
NULL
;
memcpy
(
d
,
s
,
l
);
d
[
l
]
=
0
;
return
d
;
}