oboeru

a collection of simple, scriptable flashcard programs
git clone anongit@rnpnr.xyz:oboeru.git
Log | Files | Refs | Feed | README | LICENSE

util.c (491B)


      1 /* See LICENSE for license details. */
      2 #include <stdarg.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 #include "util.h"
      7 
      8 void
      9 die(const char *errstr, ...)
     10 {
     11 	va_list ap;
     12 
     13 	va_start(ap, errstr);
     14 	vfprintf(stderr, errstr, ap);
     15 	va_end(ap);
     16 
     17 	exit(1);
     18 }
     19 
     20 void *
     21 xmalloc(size_t s)
     22 {
     23 	void *p;
     24 
     25 	if (!(p = malloc(s)))
     26 		die("malloc()\n");
     27 
     28 	return p;
     29 }
     30 
     31 void *
     32 xreallocarray(void *o, size_t n, size_t s)
     33 {
     34 	void *new;
     35 
     36 	if (!(new = reallocarray(o, n, s)))
     37 		die("reallocarray()\n");
     38 
     39 	return new;
     40 }