1 /* 2 * (C) Copyright 2000 3 * Murray Jensen <Murray.Jensen@csiro.au> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <string.h> 11 #include <errno.h> 12 #include "error.h" 13 14 char *pname; 15 16 void 17 Warning(char *fmt, ...) 18 { 19 va_list args; 20 21 fprintf(stderr, "%s: WARNING: ", pname); 22 23 va_start(args, fmt); 24 vfprintf(stderr, fmt, args); 25 va_end(args); 26 27 fprintf(stderr, "\n"); 28 } 29 30 void 31 Error(char *fmt, ...) 32 { 33 va_list args; 34 35 fprintf(stderr, "%s: ERROR: ", pname); 36 37 va_start(args, fmt); 38 vfprintf(stderr, fmt, args); 39 va_end(args); 40 41 fprintf(stderr, "\n"); 42 43 exit(1); 44 } 45 46 void 47 Perror(char *fmt, ...) 48 { 49 va_list args; 50 int e = errno; 51 char *p; 52 53 fprintf(stderr, "%s: ERROR: ", pname); 54 55 va_start(args, fmt); 56 vfprintf(stderr, fmt, args); 57 va_end(args); 58 59 if ((p = strerror(e)) == NULL || *p == '\0') 60 fprintf(stderr, ": Unknown Error (%d)\n", e); 61 else 62 fprintf(stderr, ": %s\n", p); 63 64 exit(1); 65 } 66