2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <sys/types.h>
16 static char *shell = NULL;
19 error(char *errstr, ...) {
22 vfprintf(stderr, errstr, ap);
28 bad_malloc(unsigned int size)
30 fprintf(stderr, "fatal: could not malloc() %d bytes\n",
36 emallocz(unsigned int size)
38 void *res = calloc(1, size);
45 emalloc(unsigned int size)
47 void *res = malloc(size);
54 erealloc(void *ptr, unsigned int size)
56 void *res = realloc(ptr, size);
63 estrdup(const char *str)
65 void *res = strdup(str);
67 bad_malloc(strlen(str));
72 failed_assert(char *a, char *file, int line)
74 fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
79 swap(void **p1, void **p2)
87 spawn(Display *dpy, const char *cmd)
89 if(!shell && !(shell = getenv("SHELL")))
97 close(ConnectionNumber(dpy));
99 fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
100 execlp(shell, shell, "-c", cmd, NULL);
101 fprintf(stderr, "gridwm: execlp %s", cmd);
110 pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
115 if(!shell && !(shell = getenv("SHELL")))
121 if(pipe(pfd) == -1) {
128 close(ConnectionNumber(dpy));
130 dup2(pfd[1], STDOUT_FILENO);
133 execlp(shell, shell, "-c", cmd, NULL);
134 fprintf(stderr, "gridwm: execlp %s", cmd);
141 if((l = read(pfd[0], buf + n, len - n)) < 1)