dwm-custom/util.c

37 lines
517 B
C
Raw Normal View History

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