Root/
Source at commit 1274 created 12 years 11 months ago. By meklort, Module changes, makefile changes. | |
---|---|
1 | /*␊ |
2 | * strndup.c␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | ␊ |
7 | char *strndup(const char *s, size_t n)␊ |
8 | {␊ |
9 | ␉int l = n > strlen(s) ? strlen(s) + 1 : n + 1;␊ |
10 | ␉char *d = malloc(l);␊ |
11 | ␊ |
12 | ␉if (d)␊ |
13 | ␉␉memcpy(d, s, l);␊ |
14 | ␉d[n] = '\0';␊ |
15 | ␉return d;␊ |
16 | }␊ |
17 |