sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

eprintf.c (832B)


      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 char *argv0;
     10 
     11 static void xvprintf(const char *, va_list);
     12 
     13 void
     14 eprintf(const char *fmt, ...)
     15 {
     16 	va_list ap;
     17 
     18 	va_start(ap, fmt);
     19 	xvprintf(fmt, ap);
     20 	va_end(ap);
     21 
     22 	exit(1);
     23 }
     24 
     25 void
     26 enprintf(int status, const char *fmt, ...)
     27 {
     28 	va_list ap;
     29 
     30 	va_start(ap, fmt);
     31 	xvprintf(fmt, ap);
     32 	va_end(ap);
     33 
     34 	exit(status);
     35 }
     36 
     37 void
     38 weprintf(const char *fmt, ...)
     39 {
     40 	va_list ap;
     41 
     42 	va_start(ap, fmt);
     43 	xvprintf(fmt, ap);
     44 	va_end(ap);
     45 }
     46 
     47 void
     48 xvprintf(const char *fmt, va_list ap)
     49 {
     50 	if (argv0 && strncmp(fmt, "usage", strlen("usage")))
     51 		fprintf(stderr, "%s: ", argv0);
     52 
     53 	vfprintf(stderr, fmt, ap);
     54 
     55 	if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
     56 		fputc(' ', stderr);
     57 		perror(NULL);
     58 	}
     59 }