]> arthur.barton.de Git - ngircd-alex.git/blob - src/portab/strndup.c
Test suite/platformtest.sh: Detect when tests have been skipped
[ngircd-alex.git] / src / portab / strndup.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  */
4
5 #include "portab.h"
6
7 /**
8  * @file
9  * strndup() implementation. Public domain.
10  */
11
12 #ifndef HAVE_STRNDUP
13
14 #include <string.h>
15 #include <stdlib.h>
16 #include <sys/types.h>
17
18 GLOBAL char *
19 strndup(const char *s, size_t maxlen)
20 {
21         char *dup;
22         size_t len = strlen(s);
23
24         if (len > maxlen)
25                 len = maxlen;
26         len++;
27         dup = malloc(len);
28         if (dup)
29                 strlcpy(dup, s, len);
30
31         return dup;
32 }
33
34 #endif