]> arthur.barton.de Git - ngircd-alex.git/blob - src/portab/strdup.c
strdup.c: Code cleanup
[ngircd-alex.git] / src / portab / strdup.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  */
4
5 #include "portab.h"
6
7 /**
8  * @file
9  * strdup() implementation. Public domain.
10  */
11
12 #ifndef HAVE_STRDUP
13
14 #include "imp.h"
15 #include <string.h>
16 #include <stdlib.h>
17 #include <sys/types.h>
18
19 #include "exp.h"
20
21 GLOBAL char *
22 strdup(const char *s)
23 {
24         char *dup;
25         size_t len = strlen(s);
26         size_t alloc = len + 1;
27
28         if (len >= alloc)
29                 return NULL;
30         dup = malloc(alloc);
31         if (dup)
32                 strlcpy(dup, s, alloc );
33
34         return dup;
35 }
36
37 #endif