X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fportab%2Fstrndup.c;fp=src%2Fportab%2Fstrndup.c;h=d6e01c943299e9b696731b182d3893bb2686b148;hp=0000000000000000000000000000000000000000;hb=6ac5a82eecb76ec35f3f484149ad668073a52620;hpb=086cf3a2723e2dcc8e1acf49d166e254fe22e7cf 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 +#include +#include + +#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 +