sdhcp

simple dhcp client
git clone git://git.2f30.org/sdhcp
Log | Files | Refs | LICENSE

eprintf.c (1018B)


      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(1, 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 	if (strncmp(fmt, "usage", strlen("usage")))
     37 		fprintf(stderr, "%s: ", argv0);
     38 
     39 	vfprintf(stderr, fmt, ap);
     40 
     41 	if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
     42 		fputc(' ', stderr);
     43 		perror(NULL);
     44 	}
     45 
     46 	exit(status);
     47 }
     48 
     49 void
     50 weprintf(const char *fmt, ...)
     51 {
     52 	va_list ap;
     53 
     54 	if (strncmp(fmt, "usage", strlen("usage")))
     55 		fprintf(stderr, "%s: ", argv0);
     56 
     57 	va_start(ap, fmt);
     58 	vfprintf(stderr, fmt, ap);
     59 	va_end(ap);
     60 
     61 	if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
     62 		fputc(' ', stderr);
     63 		perror(NULL);
     64 	}
     65 }