aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

eprintf.c (811B)


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