Add STRDUP macro to mirror MALLOC/CALLOC

Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
This commit is contained in:
Aaron Griffin 2007-11-06 22:50:21 -06:00
parent 2ee90ddae2
commit d0d58489ff
1 changed files with 2 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h> /* struct stat */
@ -44,6 +45,7 @@
#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
#define STRDUP(r, s, action) do { r = strdup(s); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } while(0)
#define FREE(p) do { if(p) { free(p); p = NULL; } } while(0)