Return to strndup.c CVS log | Up to [local] / ircnowd / src / portab |
File: [local] / ircnowd / src / portab / strndup.c (download)
Revision 1.1, Thu May 16 11:07:06 2024 UTC (4 months ago) by tomglok
Initial revision |
/* * ngIRCd -- The Next Generation IRC Daemon */ #include "portab.h" /** * @file * strndup() implementation. Public domain. */ #ifndef HAVE_STRNDUP #include <string.h> #include <stdlib.h> #include <sys/types.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