dwm-meillo

view util.c @ 63:f14858218641

searching for a better way to discard enter notifies
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 13:03:53 +0200
parents 466591c2f967
children 50450aa24a46
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 error(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 swap(void **p1, void **p2)
43 {
44 void *tmp = *p1;
45 *p1 = *p2;
46 *p2 = tmp;
47 }
49 void
50 spawn(Arg *arg)
51 {
52 char **argv = (char **)arg->argv;
53 if(!argv || !argv[0])
54 return;
55 if(fork() == 0) {
56 if(fork() == 0) {
57 if(dpy)
58 close(ConnectionNumber(dpy));
59 setsid();
60 execvp(argv[0], argv);
61 fprintf(stderr, "dwm: execvp %s", argv[0]);
62 perror(" failed");
63 }
64 exit (0);
65 }
66 wait(0);
67 }