Sign in
googlers
/
maze
/
klibc
/
0bd18d54159154f4af1c478a854c884cd80ecf0b
/
.
/
usr
/
klibc
/
strndup.c
blob: e4814be09e007cb4d511240ce551b6064bf7022a [
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
[
n
]
=
'\0'
;
return
d
;
}