>From 59ab03dc28a6d20283ac1cf47665b690deff3954 Mon Sep 17 00:00:00 2001 From: Jakob Kramer <jakob.kra...@gmx.de> Date: Wed, 11 Feb 2015 01:40:52 +0100 Subject: [PATCH 1/3] add en*alloc functions
--- libutil/ealloc.c | 38 +++++++++++++++++++++++++++++++------- util.h | 6 +++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/libutil/ealloc.c b/libutil/ealloc.c index 05bdd62..8e2f21e 100644 --- a/libutil/ealloc.c +++ b/libutil/ealloc.c @@ -7,41 +7,65 @@ void * ecalloc(size_t nmemb, size_t size) { + return encalloc(1, nmemb, size); +} + +void * +emalloc(size_t size) +{ + return enmalloc(1, size); +} + +void * +erealloc(void *p, size_t size) +{ + return enrealloc(1, p, size); +} + +char * +estrdup(const char *s) +{ + return enstrdup(1, s); +} + +void * +encalloc(int status, size_t nmemb, size_t size) +{ void *p; p = calloc(nmemb, size); if (!p) - eprintf("calloc: out of memory\n"); + enprintf(status, "calloc: out of memory\n"); return p; } void * -emalloc(size_t size) +enmalloc(int status, size_t size) { void *p; p = malloc(size); if (!p) - eprintf("malloc: out of memory\n"); + enprintf(status, "malloc: out of memory\n"); return p; } void * -erealloc(void *p, size_t size) +enrealloc(int status, void *p, size_t size) { p = realloc(p, size); if (!p) - eprintf("realloc: out of memory\n"); + enprintf(status, "realloc: out of memory\n"); return p; } char * -estrdup(const char *s) +enstrdup(int status, const char *s) { char *p; p = strdup(s); if (!p) - eprintf("strdup: out of memory\n"); + enprintf(status, "strdup: out of memory\n"); return p; } diff --git a/util.h b/util.h index f9175b2..2efcd89 100644 --- a/util.h +++ b/util.h @@ -22,9 +22,13 @@ char *agetcwd(void); void apathmax(char **, long *); void *ecalloc(size_t, size_t); -void *emalloc(size_t size); +void *emalloc(size_t); void *erealloc(void *, size_t); char *estrdup(const char *); +void *encalloc(int, size_t, size_t); +void *enmalloc(int, size_t); +void *enrealloc(int, void *, size_t); +char *enstrdup(int, const char *); void enprintf(int, const char *, ...); void eprintf(const char *, ...); -- 1.9.1