diff options
author | Anselm R. Garbe <arg@10kloc.org> | 2006-10-12 12:58:34 +0200 |
---|---|---|
committer | Anselm R. Garbe <arg@10kloc.org> | 2006-10-12 12:58:34 +0200 |
commit | 3d25a327aad95e38ecd1642af58a49fc555a9d01 (patch) | |
tree | 46a6cf35254a8418bb2bedd5fe8b745f1f601643 | |
parent | d78bcf247fe03e23e7980b246ccf5d57d256ecfc (diff) |
simplified util.c
-rw-r--r-- | util.c | 29 |
1 files changed, 10 insertions, 19 deletions
@@ -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 | |||
14 | static void | ||
15 | badmalloc(unsigned int size) { | ||
16 | eprint("fatal: could not malloc() %u bytes\n", size); | ||
17 | } | ||
18 | |||
19 | /* extern */ | ||
20 | |||
21 | void * | 12 | void * |
22 | emalloc(unsigned int size) { | 13 | emalloc(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 | |||
21 | char * | ||
22 | estrdup(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 | |||
40 | char * | ||
41 | estrdup(const char *str) { | ||
42 | void *res = strdup(str); | ||
43 | |||
44 | if(!res) | ||
45 | badmalloc(strlen(str)); | ||
46 | return res; | ||
47 | } | ||