Sign in
googlers
/
maze
/
klibc
/
a83efd0838c3bb2a6f5c3b095a01b45014b8414e
/
.
/
usr
/
klibc
/
strndup.c
blob: 8b5974a3d2437517fd19aeae75251719113e89e0 [
file
] [
log
] [
blame
]
/*
* strndup.c
*/
#include
<string.h>
#include
<stdlib.h>
char
*
strndup
(
const
char
*
s
,
size_t
n
)
{
int
l
=
n
>
strlen
(
s
)
?
strlen
(
s
)
+
1
:
n
+
1
;
char
*
d
=
malloc
(
l
);
if
(
d
)
memcpy
(
d
,
s
,
l
);
d
[
n
]
=
'\0'
;
return
d
;
}