diff -r 000000000000 -r c2f4c0285180 gclib/strfuncs.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gclib/strfuncs.c Tue Jan 24 23:54:05 2012 +0000 @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +/* + * Like strndup, but only returns NULL if str is NULL. + * Note that this routine copies n bytes rather than n characters. + */ +char *str_ndup(const char *str,size_t n) +{ + char *dup; + if (!str) + return NULL; + dup=mem_alloc0(n+1,1); + strncpy(dup,str,n); + return dup; +} + +/* + * Like strdup, but only returns NULL if str is NULL. + */ +char *str_dup(const char *str) +{ + return str_ndup(str,strlen(str)); +}