diff th_string.c @ 79:e36df57c5b0f

Use th_strdup() again.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Dec 2008 16:03:53 +0200
parents e47955d42b55
children 69aed051f84d
line wrap: on
line diff
--- a/th_string.c	Thu Dec 18 14:34:44 2008 +0200
+++ b/th_string.c	Wed Dec 24 16:03:53 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)