Sign in
cobalt
/
cobalt
/
5864f47b864e8bb7b417f15981009ad93bdff2ac
/
.
/
third_party
/
musl
/
src
/
string
/
strndup.c
blob: 617d27ba9e65ba384fa97433e90b1632015ee998 [
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
;
}