stacinhtml

Static C in HTML - simple static site generator
git clone git://git.kocotian.pl/stacinhtml.git
Log | Files | Refs | README | LICENSE

util.c (526B)


      1 /* See licenses/LIBSL file for copyright and license details. */
      2 #include <stdarg.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 #include "util.h"
      8 
      9 void *
     10 ecalloc(size_t nmemb, size_t size)
     11 {
     12 	void *p;
     13 
     14 	if (!(p = calloc(nmemb, size)))
     15 		die("calloc:");
     16 	return p;
     17 }
     18 
     19 void
     20 die(const char *fmt, ...)
     21 {
     22 	va_list ap;
     23 
     24 	va_start(ap, fmt);
     25 	vfprintf(stderr, fmt, ap);
     26 	va_end(ap);
     27 
     28 	if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
     29 		fputc(' ', stderr);
     30 		perror(NULL);
     31 	} else {
     32 		fputc('\n', stderr);
     33 	}
     34 
     35 	exit(1);
     36 }