2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <sys/types.h>
17 error(char *errstr, ...) {
20 vfprintf(stderr, errstr, ap);
26 bad_malloc(unsigned int size)
28 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
34 emallocz(unsigned int size)
36 void *res = calloc(1, size);
43 emalloc(unsigned int size)
45 void *res = malloc(size);
52 erealloc(void *ptr, unsigned int size)
54 void *res = realloc(ptr, size);
61 estrdup(const char *str)
63 void *res = strdup(str);
65 bad_malloc(strlen(str));
70 failed_assert(char *a, char *file, int line)
72 fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
77 swap(void **p1, void **p2)
85 spawn(Display *dpy, char *argv[])
92 close(ConnectionNumber(dpy));
94 execvp(argv[0], argv);
95 fprintf(stderr, "gridwm: execvp %s", argv[0]);
104 pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[])
109 if(!argv || !argv[0])
112 if(pipe(pfd) == -1) {
119 close(ConnectionNumber(dpy));
121 dup2(pfd[1], STDOUT_FILENO);
124 execvp(argv[0], argv);
125 fprintf(stderr, "gridwm: execvp %s", argv[0]);
132 if((l = read(pfd[0], buf + n, len - n)) < 1)
137 buf[n < len ? n : len - 1] = 0;