X-Git-Url: https://git.danieliu.xyz/?p=dwm.git;a=blobdiff_plain;f=util.c;h=6b703e9b8180fb32ce3e3e018a2bf0124748c797;hp=94590f9233e397ccccb0f971b3376befe8ddfab7;hb=56a31dc4a7be459e3a1ea06d45427e1a4087a1a6;hpb=dc5d967ee61046f899b3b49daeb9268c8161844a diff --git a/util.c b/util.c index 94590f9..6b703e9 100644 --- a/util.c +++ b/util.c @@ -1,64 +1,33 @@ -/* - * (C)opyright MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ -#include "dwm.h" - +/* See LICENSE file for copyright and license details. */ #include #include #include -#include -#include - -/* static */ - -static void -bad_malloc(unsigned int size) -{ - fprintf(stderr, "fatal: could not malloc() %d bytes\n", - (int) size); - exit(EXIT_FAILURE); -} +#include -/* extern */ +#include "util.h" void * -emallocz(unsigned int size) +ecalloc(size_t nmemb, size_t size) { - void *res = calloc(1, size); + void *p; - if(!res) - bad_malloc(size); - return res; + if (!(p = calloc(nmemb, size))) + perror(NULL); + return p; } void -eprint(const char *errstr, ...) { +die(const char *fmt, ...) { va_list ap; - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); va_end(ap); - exit(EXIT_FAILURE); -} -void -spawn(Arg *arg) -{ - char **argv = (char **)arg->argv; - - if(!argv || !argv[0]) - return; - if(fork() == 0) { - if(fork() == 0) { - if(dpy) - close(ConnectionNumber(dpy)); - setsid(); - execvp(argv[0], argv); - fprintf(stderr, "dwm: execvp %s", argv[0]); - perror(" failed"); - } - exit(EXIT_FAILURE); + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); } - wait(0); + + exit(1); }