Sign in
kernel
/
pub
/
scm
/
linux
/
kernel
/
git
/
bwh
/
klibc
/
201dabf78546ca712d3541670a5d898dc199854e
/
.
/
usr
/
klibc
/
strndup.c
blob: 20eaa8b5c7f32ef49c48a8b359a3fc22342e3b0d [
file
] [
log
] [
blame
]
/*
* strndup.c
*/
#include
<string.h>
#include
<stdlib.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
;
}