wdenk | 3ba6865 | 2000-10-11 22:04:29 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <errno.h> |
| 5 | #include "error.h" |
| 6 | |
| 7 | char *pname; |
| 8 | |
| 9 | void |
| 10 | Warning(char *fmt, ...) |
| 11 | { |
| 12 | va_list args; |
| 13 | |
| 14 | fprintf(stderr, "%s: WARNING: ", pname); |
| 15 | |
| 16 | va_start(args, fmt); |
| 17 | vfprintf(stderr, fmt, args); |
| 18 | va_end(args); |
| 19 | |
| 20 | fprintf(stderr, "\n"); |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | Error(char *fmt, ...) |
| 25 | { |
| 26 | va_list args; |
| 27 | |
| 28 | fprintf(stderr, "%s: ERROR: ", pname); |
| 29 | |
| 30 | va_start(args, fmt); |
| 31 | vfprintf(stderr, fmt, args); |
| 32 | va_end(args); |
| 33 | |
| 34 | fprintf(stderr, "\n"); |
| 35 | |
| 36 | exit(1); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | Perror(char *fmt, ...) |
| 41 | { |
| 42 | va_list args; |
| 43 | int e = errno; |
| 44 | char *p; |
| 45 | |
| 46 | fprintf(stderr, "%s: ERROR: ", pname); |
| 47 | |
| 48 | va_start(args, fmt); |
| 49 | vfprintf(stderr, fmt, args); |
| 50 | va_end(args); |
| 51 | |
| 52 | if ((p = strerror(e)) == NULL || *p == '\0') |
| 53 | fprintf(stderr, ": Unknown Error (%d)\n", e); |
| 54 | else |
| 55 | fprintf(stderr, ": %s\n", p); |
| 56 | |
| 57 | exit(1); |
| 58 | } |