sbase

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

commit 2982d885332c6815b0bd424387a8bb61c8abb24d
parent 35d467d971e8d321eb99a2201b8bf1f69da48f82
Author: sin <sin@2f30.org>
Date:   Fri, 14 Nov 2014 18:09:48 +0000

Import ealloc.c from ubase

Diffstat:
MMakefile | 1+
Mutil.h | 5+++++
Autil/ealloc.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -21,6 +21,7 @@ LIB = \ util/concat.o \ util/cp.o \ util/crypt.o \ + util/ealloc.o \ util/enmasse.o \ util/eprintf.o \ util/estrtod.o \ diff --git a/util.h b/util.h @@ -17,14 +17,19 @@ extern char *argv0; char *agetcwd(void); void apathmax(char **, long *); void enmasse(int, char **, int (*)(const char *, const char *)); +void *ecalloc(size_t, size_t); +void *emalloc(size_t size); +void *erealloc(void *, size_t); void eprintf(const char *, ...); void enprintf(int, const char *, ...); +char *estrdup(const char *); double estrtod(const char *); long estrtol(const char *, int); void fnck(const char *, const char *, int (*)(const char *, const char *)); char *humansize(double); void putword(const char *); void recurse(const char *, void (*)(const char *)); + #undef strlcat size_t strlcat(char *, const char *, size_t); #undef strlcpy diff --git a/util/ealloc.c b/util/ealloc.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdlib.h> +#include <string.h> + +#include "../util.h" + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + p = calloc(nmemb, size); + if (!p) + eprintf("calloc: out of memory\n"); + return p; +} + +void * +emalloc(size_t size) +{ + void *p; + + p = malloc(size); + if (!p) + eprintf("malloc: out of memory\n"); + return p; +} + +void * +erealloc(void *p, size_t size) +{ + p = realloc(p, size); + if (!p) + eprintf("realloc: out of memory\n"); + return p; +} + +char * +estrdup(const char *s) +{ + char *p; + + p = strdup(s); + if (!p) + eprintf("strdup: out of memory\n"); + return p; +}