diff options
Diffstat (limited to 'com32/lib/strndup.c')
-rw-r--r-- | com32/lib/strndup.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/com32/lib/strndup.c b/com32/lib/strndup.c new file mode 100644 index 00000000..1b44e6f9 --- /dev/null +++ b/com32/lib/strndup.c @@ -0,0 +1,17 @@ +/* + * 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; +} |