Initial release, version 0.0.0.
[gsasl.git] / argp / strndup.c
blobf01065a533b21051c940755f020633ff2a573c0c
1 /* strndup.c
3 */
5 /* Written by Niels Möller <nisse@lysator.liu.se>
7 * This file is hereby placed in the public domain.
8 */
10 #include <stdlib.h>
11 #include <string.h>
13 char *
14 strndup (const char *s, size_t size)
16 char *r;
17 char *end = memchr(s, 0, size);
19 if (end)
20 /* Length + 1 */
21 size = end - s + 1;
23 r = malloc(size);
25 if (size)
27 memcpy(r, s, size-1);
28 r[size-1] = '\0';
30 return r;