dwm-meillo
view util.c @ 187:41f8ee33771e
small stylistic fix
author | arg@10ksloc.org |
---|---|
date | Fri, 04 Aug 2006 10:27:16 +0200 |
parents | 21071ae1fe68 |
children | 523df4a3c1c4 |
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5 #include "dwm.h"
6 #include <stdarg.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
12 /* static */
14 static void
15 bad_malloc(unsigned int size)
16 {
17 eprint("fatal: could not malloc() %u bytes\n", size);
18 }
20 /* extern */
22 void *
23 emallocz(unsigned int size)
24 {
25 void *res = calloc(1, size);
27 if(!res)
28 bad_malloc(size);
29 return res;
30 }
32 void
33 eprint(const char *errstr, ...)
34 {
35 va_list ap;
37 va_start(ap, errstr);
38 vfprintf(stderr, errstr, ap);
39 va_end(ap);
40 exit(EXIT_FAILURE);
41 }
43 void
44 spawn(Arg *arg)
45 {
46 char **argv = (char **)arg->argv;
48 if(!argv || !argv[0])
49 return;
50 if(fork() == 0) {
51 if(fork() == 0) {
52 if(dpy)
53 close(ConnectionNumber(dpy));
54 setsid();
55 execvp(argv[0], argv);
56 fprintf(stderr, "dwm: execvp %s", argv[0]);
57 perror(" failed");
58 }
59 exit(0);
60 }
61 wait(0);
62 }