Browse code

add cli_strdup()

git-svn: trunk@2472

Tomasz Kojm authored on 2006/11/02 03:16:57
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Nov  1 19:15:57 CET 2006 (tk)
2
+---------------------------------
3
+  * libclamav/others.c: add cli_strdup(), thanks to NJH
4
+
1 5
 Wed Nov  1 18:59:48 CET 2006 (tk)
2 6
 ---------------------------------
3 7
   * libclamav: add support for self-extracting MS Cabinet archives
... ...
@@ -385,12 +385,37 @@ void *cli_realloc(void *ptr, size_t size)
385 385
     alloc = realloc(ptr, size);
386 386
 
387 387
     if(!alloc) {
388
-	cli_errmsg("cli_realloc(): Can't re-allocate memory to %u byte.\n", size);
388
+	cli_errmsg("cli_realloc(): Can't re-allocate memory to %u bytes.\n", size);
389 389
 	perror("realloc_problem");
390 390
 	return NULL;
391 391
     } else return alloc;
392 392
 }
393 393
 
394
+char *cli_strdup(const char *s)
395
+{
396
+        char *alloc;
397
+
398
+
399
+    if(s == NULL) {
400
+        cli_errmsg("cli_strdup(): s == NULL. Please report to http://bugs.clamav.net\n");
401
+        return NULL;
402
+    }
403
+
404
+#if defined(_MSC_VER) && defined(_DEBUG)
405
+    alloc = _strdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__);
406
+#else
407
+    alloc = strdup(s);
408
+#endif
409
+
410
+    if(!alloc) {
411
+        cli_errmsg("cli_strdup(): Can't allocate memory (%u bytes).\n", strlen(s));
412
+        perror("strdup_problem");
413
+        return NULL;
414
+    }
415
+
416
+    return alloc;
417
+}
418
+
394 419
 unsigned int cli_rndnum(unsigned int max)
395 420
 {
396 421
     struct timeval tv;
... ...
@@ -130,6 +130,7 @@ void cli_dbgmsg(const char *str, ...);
130 130
 void *cli_malloc(size_t nmemb);
131 131
 void *cli_calloc(size_t nmemb, size_t size);
132 132
 void *cli_realloc(void *ptr, size_t size);
133
+char *cli_strdup(const char *s);
133 134
 int cli_rmdirs(const char *dirname);
134 135
 unsigned char *cli_md5digest(int desc);
135 136
 char *cli_md5stream(FILE *fs, unsigned char *digcpy);