Mercurial > hg > th-libs
changeset 8:acc2a8035dd5
Re-add th_strdup().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Dec 2008 16:03:04 +0200 |
parents | 41885619fc79 |
children | 62f8c657734d |
files | th_string.c th_string.h |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-) [+] |
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)
--- a/th_string.h Wed Nov 26 22:17:02 2008 +0200 +++ b/th_string.h Wed Dec 24 16:03:04 2008 +0200 @@ -48,8 +48,9 @@ int th_strncasecmp(char *, char *, size_t); void th_strip_ctrlchars(char *); -int th_pstrcpy(char **, char *); -int th_pstrcat(char **, char *); +char *th_strdup(const char *); +int th_pstrcpy(char **, char *); +int th_pstrcat(char **, char *); char *th_findnext(char *, size_t *); char *th_findsep(char *, size_t *, char);