[hackers] [ubase] Add ealloc.c with wrappers for emalloc() and friends || sin
commit 550b655d987f46f09861c0239c0c11a86db5d09c
Author: sin <sin_AT_2f30.org>
Date: Wed Apr 30 13:01:56 2014 +0100
Add ealloc.c with wrappers for emalloc() and friends
Re-organize util.h as well.
diff --git a/Makefile b/Makefile
index 56945be..ac61c7d 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -7,6 +7,7 @@ HDR = arg.h config.def.h proc.h reboot.h util.h
LIB = \
util/agetcwd.o \
util/apathmax.o \
+ util/ealloc.o \
util/eprintf.o \
util/estrtol.o \
util/explicit_bzero.o \
diff --git a/util.h b/util.h
index 416bb4c..0ed7f6b 100644
--- a/util.h
+++ b/util.h
_AT_@ -4,21 +4,47 @@
#define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
#define LEN(x) (sizeof (x) / sizeof *(x))
+/* eprintf.c */
extern char *argv0;
+/* agetcwd.c */
char *agetcwd(void);
+
+/* apathmax.c */
void apathmax(char **, long *);
-void devtotty(int, int *, int *);
+
+/* eprintf.c */
void enprintf(int, const char *, ...);
void eprintf(const char *, ...);
+void weprintf(const char *, ...);
+
+/* ealloc.c */
+void *ecalloc(size_t, size_t);
+void *emalloc(size_t size);
+void *erealloc(void *, size_t);
+char *estrdup(const char *);
+
+/* estrtol.c */
long estrtol(const char *, int);
+
+/* explicit_bzero.c */
#undef explicit_bzero
void explicit_bzero(void *, size_t);
+
+/* putword.c */
void putword(const char *);
+
+/* recurse.c */
void recurse(const char *, void (*)(const char *));
+
+/* strlcpy.c */
#undef strlcat
size_t strlcat(char *, const char *, size_t);
+
+/* strlcat.c */
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
+
+/* tty.c */
+void devtotty(int, int *, int *);
char *ttytostr(int, int);
-void weprintf(const char *, ...);
diff --git a/util/ealloc.c b/util/ealloc.c
new file mode 100644
index 0000000..bb124f4
--- /dev/null
+++ b/util/ealloc.c
_AT_@ -0,0 +1,46 @@
+/* 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
");
+ return p;
+}
+
+void *
+emalloc(size_t size)
+{
+ void *p;
+
+ p = malloc(size);
+ if (!p)
+ eprintf("malloc: out of memory
");
+ return p;
+}
+
+void *
+erealloc(void *p, size_t size)
+{
+ p = realloc(p, size);
+ if (!p)
+ eprintf("realloc: out of memory
");
+ return p;
+}
+
+char *
+estrdup(const char *s)
+{
+ char *p;
+
+ p = strdup(s);
+ if (!p)
+ eprintf("strdup: out of memory
");
+ return p;
+}
Received on Wed Apr 30 2014 - 14:12:15 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 30 2014 - 14:24:11 CEST