svkbd

simple virtual keyboard
git clone git://git.suckless.org/svkbd
Log | Files | Refs | README | LICENSE

util.c (615B)


      1 /* See LICENSE 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 char *
     20 estrdup(const char *s)
     21 {
     22 	char *p;
     23 
     24 	if (!(p = strdup(s)))
     25 		die("strdup:");
     26 	return p;
     27 }
     28 
     29 void
     30 die(const char *fmt, ...)
     31 {
     32 	va_list ap;
     33 
     34 	va_start(ap, fmt);
     35 	vfprintf(stderr, fmt, ap);
     36 	va_end(ap);
     37 
     38 	if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
     39 		fputc(' ', stderr);
     40 		perror(NULL);
     41 	} else {
     42 		fputc('\n', stderr);
     43 	}
     44 
     45 	exit(1);
     46 }