sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 08e93dd4f5e315cdfc5a44a7ae17d702207f67d3
parent 51680535ce4d929a40e2ffa85d64c2aa6f57f90f
Author: Jakob Kramer <jakob.kramer@gmx.de>
Date:   Wed, 11 Feb 2015 01:40:52 +0100

add en*alloc functions

Diffstat:
Mlibutil/ealloc.c | 38+++++++++++++++++++++++++++++++-------
Mutil.h | 6+++++-
2 files changed, 36 insertions(+), 8 deletions(-)

diff --git 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 @@ -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 *, ...);