aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/util.c b/util.c
index b4b163a..b7798d2 100644
--- a/util.c
+++ b/util.c
@@ -9,21 +9,21 @@
9#include <sys/wait.h> 9#include <sys/wait.h>
10#include <unistd.h> 10#include <unistd.h>
11 11
12/* static */
13
14static void
15badmalloc(unsigned int size) {
16 eprint("fatal: could not malloc() %u bytes\n", size);
17}
18
19/* extern */
20
21void * 12void *
22emalloc(unsigned int size) { 13emalloc(unsigned int size) {
23 void *res = malloc(size); 14 void *res = malloc(size);
24 15
25 if(!res) 16 if(!res)
26 badmalloc(size); 17 eprint("fatal: could not malloc() %u bytes\n", size);
18 return res;
19}
20
21char *
22estrdup(const char *str) {
23 void *res = strdup(str);
24
25 if(!res)
26 eprint("fatal: could not malloc() %u bytes\n", strlen(str));
27 return res; 27 return res;
28} 28}
29 29
@@ -36,12 +36,3 @@ eprint(const char *errstr, ...) {
36 va_end(ap); 36 va_end(ap);
37 exit(EXIT_FAILURE); 37 exit(EXIT_FAILURE);
38} 38}
39
40char *
41estrdup(const char *str) {
42 void *res = strdup(str);
43
44 if(!res)
45 badmalloc(strlen(str));
46 return res;
47}