pinentry-dmenu/util.c

36 lines
574 B
C
Raw Normal View History

2021-07-26 11:20:50 +00: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 *
ecalloc(size_t nmemb, size_t size)
{
void *p;
2021-07-26 11:20:50 +00:00
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
2021-07-26 11:20:50 +00:00
}
void
die(const char *fmt, ...) {
va_list ap;
2021-07-26 11:20:50 +00:00
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
2021-07-26 11:20:50 +00:00
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr);
perror(NULL);
} else {
fputc('\n', stderr);
}
2021-07-26 11:20:50 +00:00
exit(1);
2021-07-26 11:20:50 +00:00
}