source:
bootcd/isolinux/syslinux-6.03/com32/lib/strndup.c
Last change on this file was e16e8f2, checked in by , 3 years ago | |
---|---|
|
|
File size: 242 bytes |
Rev | Line | |
---|---|---|
[e16e8f2] | 1 | /* |
2 | * strndup.c | |
3 | */ | |
4 | ||
5 | #include <string.h> | |
6 | #include <stdlib.h> | |
7 | ||
8 | char *strndup(const char *s, size_t n) | |
9 | { | |
10 | int l = n > strlen(s) ? strlen(s) + 1 : n + 1; | |
11 | char *d = malloc(l); | |
12 | ||
13 | if (d) | |
14 | memcpy(d, s, l); | |
15 | d[n] = '\0'; | |
16 | return d; | |
17 | } |
Note: See TracBrowser
for help on using the repository browser.