repo.or.cz
/
gsasl.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Initial release, version 0.0.0.
[gsasl.git]
/
argp
/
strndup.c
blob
f01065a533b21051c940755f020633ff2a573c0c
1
/* strndup.c
2
*
3
*/
4
5
/* Written by Niels Möller <nisse@lysator.liu.se>
6
*
7
* This file is hereby placed in the public domain.
8
*/
9
10
#include <stdlib.h>
11
#include <string.h>
12
13
char
*
14
strndup
(
const char
*
s
,
size_t
size
)
15
{
16
char
*
r
;
17
char
*
end
=
memchr
(
s
,
0
,
size
);
18
19
if
(
end
)
20
/* Length + 1 */
21
size
=
end
-
s
+
1
;
22
23
r
=
malloc
(
size
);
24
25
if
(
size
)
26
{
27
memcpy
(
r
,
s
,
size
-
1
);
28
r
[
size
-
1
] =
'\0'
;
29
}
30
return
r
;
31
}