diff options
| author | Federico G. Schwindt <fgsch@lodoss.net> | 2013-08-26 10:47:04 +0100 |
|---|---|---|
| committer | Federico G. Schwindt <fgsch@lodoss.net> | 2013-08-26 10:47:04 +0100 |
| commit | 6ac5a82eecb76ec35f3f484149ad668073a52620 (patch) | |
| tree | 1e83126d7bffd98ee7a0e4ee9287e760d3ab4629 /src/portab/strndup.c | |
| parent | 086cf3a2723e2dcc8e1acf49d166e254fe22e7cf (diff) | |
| download | ngircd-6ac5a82eecb76ec35f3f484149ad668073a52620.tar.gz ngircd-6ac5a82eecb76ec35f3f484149ad668073a52620.zip | |
private strndup() implementation in case libc does not provide it
Diffstat (limited to 'src/portab/strndup.c')
| -rw-r--r-- | src/portab/strndup.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/portab/strndup.c b/src/portab/strndup.c new file mode 100644 index 00000000..d6e01c94 --- /dev/null +++ b/src/portab/strndup.c @@ -0,0 +1,37 @@ +/* + * ngIRCd -- The Next Generation IRC Daemon + */ + +#include "portab.h" + +/** + * @file + * strndup() implementation. Public domain. + */ + +#ifndef HAVE_STRNDUP + +#include "imp.h" +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> + +#include "exp.h" + +GLOBAL char * +strndup(const char *s, size_t maxlen) +{ + char *dup; + size_t len = strlen(s); + + if (len > maxlen) + len = maxlen; + len++; + dup = malloc(len); + if (dup) + strlcpy(dup, s, len); + return dup; +} + +#endif + |