made function signatures more consistent to my coding style
[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         eprint("fatal: could not malloc() %u bytes\n", size);
18 }
19
20 /* extern */
21
22 void *
23 emalloc(unsigned int size) {
24         void *res = malloc(size);
25         if(!res)
26                 badmalloc(size);
27         return res;
28 }
29
30 void
31 eprint(const char *errstr, ...) {
32         va_list ap;
33
34         va_start(ap, errstr);
35         vfprintf(stderr, errstr, ap);
36         va_end(ap);
37         exit(EXIT_FAILURE);
38 }
39
40 char *
41 estrdup(const char *str) {
42         void *res = strdup(str);
43         if(!res)
44                 badmalloc(strlen(str));
45         return res;
46 }