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