[fix] parent_row after chdir to a bookmark
[sfm.git] / util.c
blob4aca4e075ec7c841c4534bd1f78459b555a6fd7f
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 #include "util.h"
10 void *
11 ecalloc(size_t nmemb, size_t size)
13 void *p;
14 p = calloc(nmemb, size);
15 FAIL_IF(p == NULL, "calloc");
16 return p;
19 void *
20 erealloc(void *p, size_t len)
22 if ((p = realloc(p, len)) == NULL)
23 die("realloc: %s\n", strerror(errno));
24 return p;
27 void
28 die(const char *fmt, ...)
30 va_list ap;
32 va_start(ap, fmt);
33 (void)vfprintf(stderr, fmt, ap);
34 va_end(ap);
36 if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') {
37 (void)fputc(' ', stderr);
38 perror(NULL);
39 } else {
40 (void)fputc('\n', stderr);
43 exit(EXIT_FAILURE);