ali@0: #include ali@0: #include ali@5: #include ali@5: #include ali@0: ali@0: /* ali@0: * Like strndup, but only returns NULL if str is NULL. ali@0: * Note that this routine copies n bytes rather than n characters. ali@0: */ ali@0: char *str_ndup(const char *str,size_t n) ali@0: { ali@0: char *dup; ali@0: if (!str) ali@0: return NULL; ali@0: dup=mem_alloc0(n+1,1); ali@0: strncpy(dup,str,n); ali@0: return dup; ali@0: } ali@0: ali@0: /* ali@0: * Like strdup, but only returns NULL if str is NULL. ali@0: */ ali@0: char *str_dup(const char *str) ali@0: { ali@0: return str_ndup(str,strlen(str)); ali@0: }