2012-12-08 10:13:01 +01:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-10-20 23:34:49 +02:00
|
|
|
#include <string.h>
|
2012-12-08 10:13:01 +01:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
2020-09-04 09:46:51 +02:00
|
|
|
void*
|
2015-10-20 23:34:49 +02:00
|
|
|
ecalloc(size_t nmemb, size_t size)
|
|
|
|
{
|
2020-09-04 09:46:51 +02:00
|
|
|
void* p;
|
2015-10-20 23:34:49 +02:00
|
|
|
|
2020-09-04 09:46:51 +02:00
|
|
|
if (!(p = calloc(nmemb, size)))
|
|
|
|
die("calloc:");
|
|
|
|
return p;
|
2015-10-20 23:34:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-08 10:13:01 +01:00
|
|
|
void
|
2020-09-04 09:46:51 +02:00
|
|
|
die(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2012-12-08 10:13:01 +01:00
|
|
|
|
2020-09-04 09:46:51 +02:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
2012-12-08 10:13:01 +01:00
|
|
|
|
2020-09-04 09:46:51 +02:00
|
|
|
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
perror(NULL);
|
|
|
|
} else {
|
|
|
|
fputc('\n', stderr);
|
|
|
|
}
|
2015-10-20 23:34:49 +02:00
|
|
|
|
2020-09-04 09:46:51 +02:00
|
|
|
exit(1);
|
2015-10-20 23:34:49 +02:00
|
|
|
}
|