rs

FTDI serial communication program
git clone git://git.2f30.org/rs
Log | Files | Refs | README | LICENSE

eprintf.c (700B)


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