renamed bad_malloc into badmalloc as well
[dmenu.git] / util.c
1 /*
2  * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3  * See LICENSE file for license details.
4  */
5 #include "dmenu.h"
6 #include <stdarg.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/wait.h>
11 #include <unistd.h>
12
13 /* static */
14
15 static void
16 badmalloc(unsigned int size)
17 {
18         eprint("fatal: could not malloc() %u bytes\n", size);
19 }
20
21 /* extern */
22
23 void *
24 emalloc(unsigned int size)
25 {
26         void *res = malloc(size);
27         if(!res)
28                 badmalloc(size);
29         return res;
30 }
31
32 void
33 eprint(const char *errstr, ...)
34 {
35         va_list ap;
36
37         va_start(ap, errstr);
38         vfprintf(stderr, errstr, ap);
39         va_end(ap);
40         exit(EXIT_FAILURE);
41 }
42
43 char *
44 estrdup(const char *str)
45 {
46         void *res = strdup(str);
47         if(!res)
48                 badmalloc(strlen(str));
49         return res;
50 }