Xinqi Bao's Git

b7798d29f040fa57b4e91a4e86e7d0a85d96a4cf
[dmenu.git] / util.c
1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4 #include "dmenu.h"
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11
12 void *
13 emalloc(unsigned int size) {
14 void *res = malloc(size);
15
16 if(!res)
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;
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 }