annotate util.c @ 44:a36f95a4841a
changed back to urxvt, dwm has no problems with it, because it doesn't use frame windows ;)
author |
Anselm R. Garbe <garbeam@wmii.de> |
date |
Thu, 13 Jul 2006 11:49:31 +0200 |
parents |
cd30cce52b78 |
children |
466591c2f967 |
rev |
line source |
garbeam@2
|
1 /*
|
garbeam@2
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@2
|
3 * See LICENSE file for license details.
|
garbeam@2
|
4 */
|
garbeam@2
|
5
|
garbeam@2
|
6 #include <stdarg.h>
|
garbeam@2
|
7 #include <stdio.h>
|
garbeam@2
|
8 #include <stdlib.h>
|
garbeam@3
|
9 #include <string.h>
|
garbeam@5
|
10 #include <sys/types.h>
|
garbeam@5
|
11 #include <sys/wait.h>
|
garbeam@5
|
12 #include <unistd.h>
|
garbeam@5
|
13
|
garbeam@43
|
14 #include "dwm.h"
|
garbeam@2
|
15
|
garbeam@2
|
16 void
|
garbeam@33
|
17 error(const char *errstr, ...) {
|
garbeam@2
|
18 va_list ap;
|
garbeam@2
|
19 va_start(ap, errstr);
|
garbeam@2
|
20 vfprintf(stderr, errstr, ap);
|
garbeam@2
|
21 va_end(ap);
|
garbeam@2
|
22 exit(1);
|
garbeam@2
|
23 }
|
garbeam@2
|
24
|
garbeam@3
|
25 static void
|
garbeam@3
|
26 bad_malloc(unsigned int size)
|
garbeam@3
|
27 {
|
garbeam@3
|
28 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
|
garbeam@3
|
29 (int) size);
|
garbeam@3
|
30 exit(1);
|
garbeam@3
|
31 }
|
garbeam@3
|
32
|
garbeam@3
|
33 void *
|
garbeam@3
|
34 emallocz(unsigned int size)
|
garbeam@3
|
35 {
|
garbeam@3
|
36 void *res = calloc(1, size);
|
garbeam@3
|
37 if(!res)
|
garbeam@3
|
38 bad_malloc(size);
|
garbeam@3
|
39 return res;
|
garbeam@3
|
40 }
|
garbeam@3
|
41
|
garbeam@3
|
42 void *
|
garbeam@3
|
43 emalloc(unsigned int size)
|
garbeam@3
|
44 {
|
garbeam@3
|
45 void *res = malloc(size);
|
garbeam@3
|
46 if(!res)
|
garbeam@3
|
47 bad_malloc(size);
|
garbeam@3
|
48 return res;
|
garbeam@3
|
49 }
|
garbeam@3
|
50
|
garbeam@3
|
51 void *
|
garbeam@3
|
52 erealloc(void *ptr, unsigned int size)
|
garbeam@3
|
53 {
|
garbeam@3
|
54 void *res = realloc(ptr, size);
|
garbeam@3
|
55 if(!res)
|
garbeam@3
|
56 bad_malloc(size);
|
garbeam@3
|
57 return res;
|
garbeam@3
|
58 }
|
garbeam@3
|
59
|
garbeam@3
|
60 char *
|
garbeam@3
|
61 estrdup(const char *str)
|
garbeam@3
|
62 {
|
garbeam@32
|
63 char *res = strdup(str);
|
garbeam@3
|
64 if(!res)
|
garbeam@3
|
65 bad_malloc(strlen(str));
|
garbeam@3
|
66 return res;
|
garbeam@3
|
67 }
|
garbeam@3
|
68
|
garbeam@3
|
69 void
|
garbeam@3
|
70 swap(void **p1, void **p2)
|
garbeam@3
|
71 {
|
garbeam@3
|
72 void *tmp = *p1;
|
garbeam@3
|
73 *p1 = *p2;
|
garbeam@3
|
74 *p2 = tmp;
|
garbeam@3
|
75 }
|
garbeam@5
|
76
|
garbeam@5
|
77 void
|
garbeam@33
|
78 spawn(char *argv[])
|
garbeam@5
|
79 {
|
garbeam@14
|
80 if(!argv || !argv[0])
|
garbeam@5
|
81 return;
|
garbeam@5
|
82 if(fork() == 0) {
|
garbeam@5
|
83 if(fork() == 0) {
|
garbeam@5
|
84 if(dpy)
|
garbeam@5
|
85 close(ConnectionNumber(dpy));
|
garbeam@9
|
86 setsid();
|
garbeam@14
|
87 execvp(argv[0], argv);
|
garbeam@34
|
88 fprintf(stderr, "dwm: execvp %s", argv[0]);
|
garbeam@5
|
89 perror(" failed");
|
garbeam@5
|
90 }
|
garbeam@5
|
91 exit (0);
|
garbeam@5
|
92 }
|
garbeam@5
|
93 wait(0);
|
garbeam@5
|
94 }
|