xref: /openbmc/u-boot/tools/gdb/error.c (revision 1e52fea3)
1 /*
2  * (C) Copyright 2000
3  * Murray Jensen <Murray.Jensen@csiro.au>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include "error.h"
29 
30 char *pname;
31 
32 void
33 Warning(char *fmt, ...)
34 {
35     va_list args;
36 
37     fprintf(stderr, "%s: WARNING: ", pname);
38 
39     va_start(args, fmt);
40     vfprintf(stderr, fmt, args);
41     va_end(args);
42 
43     fprintf(stderr, "\n");
44 }
45 
46 void
47 Error(char *fmt, ...)
48 {
49     va_list args;
50 
51     fprintf(stderr, "%s: ERROR: ", pname);
52 
53     va_start(args, fmt);
54     vfprintf(stderr, fmt, args);
55     va_end(args);
56 
57     fprintf(stderr, "\n");
58 
59     exit(1);
60 }
61 
62 void
63 Perror(char *fmt, ...)
64 {
65     va_list args;
66     int e = errno;
67     char *p;
68 
69     fprintf(stderr, "%s: ERROR: ", pname);
70 
71     va_start(args, fmt);
72     vfprintf(stderr, fmt, args);
73     va_end(args);
74 
75     if ((p = strerror(e)) == NULL || *p == '\0')
76 	fprintf(stderr, ": Unknown Error (%d)\n", e);
77     else
78 	fprintf(stderr, ": %s\n", p);
79 
80     exit(1);
81 }
82