[hackers] [sbase] Import ealloc.c from ubase || sin

From: <git_AT_suckless.org>
Date: Fri, 14 Nov 2014 19:10:09 +0100

commit 2982d885332c6815b0bd424387a8bb61c8abb24d
Author: sin <sin_AT_2f30.org>
Date: Fri Nov 14 18:09:48 2014 +0000

    Import ealloc.c from ubase

diff --git a/Makefile b/Makefile
index 962601f..1755b98 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -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
index c3ca8a7..0385313 100644
--- a/util.h
+++ b/util.h
_AT_@ -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
new file mode 100644
index 0000000..05bdd62
--- /dev/null
+++ b/util/ealloc.c
_AT_@ -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;
+}
Received on Fri Nov 14 2014 - 19:10:09 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 14 2014 - 19:12:09 CET