[hackers] [sbase] add en*alloc functions || Jakob Kramer

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:41 +0100 (CET)

commit 08e93dd4f5e315cdfc5a44a7ae17d702207f67d3
Author: Jakob Kramer <jakob.kramer_AT_gmx.de>
Date: Wed Feb 11 01:40:52 2015 +0100

    add en*alloc functions

diff --git a/libutil/ealloc.c b/libutil/ealloc.c
index 05bdd62..8e2f21e 100644
--- a/libutil/ealloc.c
+++ b/libutil/ealloc.c
_AT_@ -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
_AT_@ -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 *, ...);
Received on Tue Mar 24 2015 - 23:53:41 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:09:22 CET