Commit | Line | Data |
---|---|---|
5d413e08 | 1 | #ifndef CONFIG_HAVE_STRNDUP |
3d2d14bc | 2 | |
5d413e08 SW |
3 | #include <stdlib.h> |
4 | #include <string.h> | |
df27f9ac | 5 | #include "strndup.h" |
b29c71c4 | 6 | |
b29c71c4 JA |
7 | char *strndup(const char *s, size_t n) |
8 | { | |
9 | char *str = malloc(n + 1); | |
10 | ||
11 | if (str) { | |
12 | strncpy(str, s, n); | |
13 | str[n] = '\0'; | |
14 | } | |
15 | ||
16 | return str; | |
17 | } | |
18 | ||
19 | #endif |