next version will contain updated copyright notice
[dmenu.git] / util.c
1 /* (C)opyright MMVII 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 void
22 eprint(const char *errstr, ...) {
23         va_list ap;
24
25         va_start(ap, errstr);
26         vfprintf(stderr, errstr, ap);
27         va_end(ap);
28         exit(EXIT_FAILURE);
29 }
30
31 char *
32 estrdup(const char *str) {
33         void *res = strdup(str);
34
35         if(!res)
36                 eprint("fatal: could not malloc() %u bytes\n", strlen(str));
37         return res;
38 }