removed useless newlines
[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 /* static */
13
14 static void
15 badmalloc(unsigned int size) {
16         eprint("fatal: could not malloc() %u bytes\n", size);
17 }
18
19 /* extern */
20
21 void *
22 emalloc(unsigned int size) {
23         void *res = malloc(size);
24
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
44         if(!res)
45                 badmalloc(strlen(str));
46         return res;
47 }