Xinqi Bao's Git

also, don't set the font all the time
[dmenu.git] / util.c
1 /* (C)opyright MMVI-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
10 void *
11 emalloc(unsigned int size) {
12 void *res = malloc(size);
13
14 if(!res)
15 eprint("fatal: could not malloc() %u bytes\n", size);
16 return res;
17 }
18
19 void
20 eprint(const char *errstr, ...) {
21 va_list ap;
22
23 va_start(ap, errstr);
24 vfprintf(stderr, errstr, ap);
25 va_end(ap);
26 exit(EXIT_FAILURE);
27 }
28
29 char *
30 estrdup(const char *str) {
31 void *res = strdup(str);
32
33 if(!res)
34 eprint("fatal: could not malloc() %u bytes\n", strlen(str));
35 return res;
36 }