diff options
Diffstat (limited to 'util.c')
| -rw-r--r-- | util.c | 51 |
1 files changed, 2 insertions, 49 deletions
| @@ -11,7 +11,7 @@ | |||
| 11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | 13 | ||
| 14 | #include "util.h" | 14 | #include "wm.h" |
| 15 | 15 | ||
| 16 | void | 16 | void |
| 17 | error(char *errstr, ...) { | 17 | error(char *errstr, ...) { |
| @@ -60,20 +60,13 @@ erealloc(void *ptr, unsigned int size) | |||
| 60 | char * | 60 | char * |
| 61 | estrdup(const char *str) | 61 | estrdup(const char *str) |
| 62 | { | 62 | { |
| 63 | void *res = strdup(str); | 63 | char *res = strdup(str); |
| 64 | if(!res) | 64 | if(!res) |
| 65 | bad_malloc(strlen(str)); | 65 | bad_malloc(strlen(str)); |
| 66 | return res; | 66 | return res; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | void | 69 | void |
| 70 | failed_assert(char *a, char *file, int line) | ||
| 71 | { | ||
| 72 | fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line); | ||
| 73 | abort(); | ||
| 74 | } | ||
| 75 | |||
| 76 | void | ||
| 77 | swap(void **p1, void **p2) | 70 | swap(void **p1, void **p2) |
| 78 | { | 71 | { |
| 79 | void *tmp = *p1; | 72 | void *tmp = *p1; |
| @@ -99,43 +92,3 @@ spawn(Display *dpy, char *argv[]) | |||
| 99 | } | 92 | } |
| 100 | wait(0); | 93 | wait(0); |
| 101 | } | 94 | } |
| 102 | |||
| 103 | void | ||
| 104 | pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]) | ||
| 105 | { | ||
| 106 | unsigned int l, n; | ||
| 107 | int pfd[2]; | ||
| 108 | |||
| 109 | if(!argv || !argv[0]) | ||
| 110 | return; | ||
| 111 | |||
| 112 | if(pipe(pfd) == -1) { | ||
| 113 | perror("pipe"); | ||
| 114 | exit(1); | ||
| 115 | } | ||
| 116 | |||
| 117 | if(fork() == 0) { | ||
| 118 | if(dpy) | ||
| 119 | close(ConnectionNumber(dpy)); | ||
| 120 | setsid(); | ||
| 121 | dup2(pfd[1], STDOUT_FILENO); | ||
| 122 | close(pfd[0]); | ||
| 123 | close(pfd[1]); | ||
| 124 | execvp(argv[0], argv); | ||
| 125 | fprintf(stderr, "gridwm: execvp %s", argv[0]); | ||
| 126 | perror(" failed"); | ||
| 127 | } | ||
| 128 | else { | ||
| 129 | l = n = 0; | ||
| 130 | close(pfd[1]); | ||
| 131 | while(n < len) { | ||
| 132 | if((l = read(pfd[0], buf + n, len - n)) < 1) | ||
| 133 | break; | ||
| 134 | n += l; | ||
| 135 | } | ||
| 136 | while(l > n); | ||
| 137 | close(pfd[0]); | ||
| 138 | buf[n < len ? n : len - 1] = 0; | ||
| 139 | } | ||
| 140 | wait(0); | ||
| 141 | } | ||
