aewl

view util.c @ 75:f08271b7cb20

rearranged several stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 16:30:50 +0200
parents 50450aa24a46
children 4bd49f404f10
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
6 #include <stdarg.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <unistd.h>
13 #include "dwm.h"
15 void
16 eprint(const char *errstr, ...) {
17 va_list ap;
18 va_start(ap, errstr);
19 vfprintf(stderr, errstr, ap);
20 va_end(ap);
21 exit(1);
22 }
24 static void
25 bad_malloc(unsigned int size)
26 {
27 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
28 (int) size);
29 exit(1);
30 }
32 void *
33 emallocz(unsigned int size)
34 {
35 void *res = calloc(1, size);
36 if(!res)
37 bad_malloc(size);
38 return res;
39 }
41 void
42 spawn(Arg *arg)
43 {
44 char **argv = (char **)arg->argv;
45 if(!argv || !argv[0])
46 return;
47 if(fork() == 0) {
48 if(fork() == 0) {
49 if(dpy)
50 close(ConnectionNumber(dpy));
51 setsid();
52 execvp(argv[0], argv);
53 fprintf(stderr, "dwm: execvp %s", argv[0]);
54 perror(" failed");
55 }
56 exit (0);
57 }
58 wait(0);
59 }