Mercurial > hg > th-libs
diff th_string.c @ 8:acc2a8035dd5
Re-add th_strdup().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Dec 2008 16:03:04 +0200 |
parents | 41885619fc79 |
children | a25f5d22483e |
line wrap: on
line diff
--- a/th_string.c Wed Nov 26 22:17:02 2008 +0200 +++ b/th_string.c Wed Dec 24 16:03:04 2008 +0200 @@ -13,6 +13,23 @@ #define LPREV (pNode->pPrev) #define LNEXT (pNode->pNext) + +/* strdup with a NULL check + */ +char *th_strdup(const char *s) +{ + char *res; + if (s == NULL) + return NULL; + + if ((res = th_malloc(strlen(s) + 1)) == NULL) + return NULL; + + strcpy(res, s); + return res; +} + + /* Allocate memory for a string with given length */ char *th_stralloc(const size_t l)