aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-04-08 23:39:10 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2023-04-08 23:39:10 +0200
commitc301a55b88a131f081a844552327c0ab85db017c (patch)
treeceff7f5058027bd260d6fe91c9ab705e40688421 /util.c
parentfe84e69990a9f156a818eb1547384812bc9db41c (diff)
connect st term api
Diffstat (limited to 'util.c')
-rw-r--r--util.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/util.c b/util.c
index 2e8a1c8..176f807 100644
--- a/util.c
+++ b/util.c
@@ -1,11 +1,36 @@
+/* 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;
+
+ if (!(p = calloc(nmemb, size)))
+ die("calloc:");
+ return p;
+}
+
void
-die(const char *error)
+die(const char *fmt, ...)
{
- fprintf(stderr, "error: %s\n", error);
- exit(-1);
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ } else {
+ fputc('\n', stderr);
+ }
+
+ exit(1);
}