dwm/util.c

33 lines
537 B
C
Raw Normal View History

/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
2025-06-27 22:24:45 -04:00
void *ecalloc(size_t nmemb, size_t size) {
void *p;
2025-06-27 22:24:45 -04:00
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
}
2025-06-27 22:24:45 -04:00
void die(const char *fmt, ...) {
va_list ap;
2025-06-27 22:24:45 -04:00
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
2025-06-27 22:24:45 -04:00
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
fputc(' ', stderr);
perror(NULL);
} else {
fputc('\n', stderr);
}
2025-06-27 22:24:45 -04:00
exit(1);
}