]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the warning and error output messages.\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | * Copyright (c) 1994 Michael L. Hitch\r | |
14 | * All rights reserved.\r | |
15 | *\r | |
16 | * Redistribution and use in source and binary forms, with or without\r | |
17 | * modification, are permitted provided that the following conditions\r | |
18 | * are met:\r | |
19 | * 1. Redistributions of source code must retain the above copyright\r | |
20 | * notice, this list of conditions and the following disclaimer.\r | |
21 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
22 | * notice, this list of conditions and the following disclaimer in the\r | |
23 | * documentation and/or other materials provided with the distribution.\r | |
24 | * 3. All advertising materials mentioning features or use of this software\r | |
25 | * must display the following acknowledgement:\r | |
26 | * This product includes software developed by Michael L. Hitch.\r | |
27 | * 4. The name of the author may not be used to endorse or promote products\r | |
28 | * derived from this software without specific prior written permission\r | |
29 | *\r | |
30 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r | |
31 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r | |
32 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r | |
33 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r | |
34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r | |
35 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r | |
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r | |
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r | |
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r | |
39 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
40 | **/\r | |
41 | #include <LibConfig.h>\r | |
42 | \r | |
43 | #include <stdarg.h>\r | |
44 | #include <stdio.h>\r | |
45 | #include <errno.h>\r | |
46 | #include <string.h>\r | |
47 | #include <stdlib.h>\r | |
48 | \r | |
49 | static void\r | |
50 | _Vdomessage(int doerrno, const char *fmt, va_list args)\r | |
51 | {\r | |
52 | fprintf(stderr, "%s: ", getprogname());\r | |
53 | if (fmt) {\r | |
54 | vfprintf(stderr, fmt, args);\r | |
55 | fprintf(stderr, ": ");\r | |
56 | }\r | |
57 | if (doerrno && errno < EMAXERRORVAL) {\r | |
58 | fprintf(stderr, "%s", strerror(errno));\r | |
59 | }\r | |
60 | fprintf(stderr, "\n");\r | |
61 | }\r | |
62 | \r | |
63 | void\r | |
64 | err(int eval, const char *fmt, ...)\r | |
65 | {\r | |
66 | va_list ap;\r | |
67 | va_start(ap, fmt);\r | |
68 | _Vdomessage(1, fmt, ap);\r | |
69 | va_end(ap);\r | |
70 | exit(eval);\r | |
71 | }\r | |
72 | \r | |
73 | void\r | |
74 | errx(int eval, const char *fmt, ...)\r | |
75 | {\r | |
76 | va_list ap;\r | |
77 | va_start(ap, fmt);\r | |
78 | _Vdomessage(0, fmt, ap);\r | |
79 | va_end(ap);\r | |
80 | exit(eval);\r | |
81 | }\r | |
82 | \r | |
83 | void\r | |
84 | warn(const char *fmt, ...)\r | |
85 | {\r | |
86 | va_list ap;\r | |
87 | va_start(ap, fmt);\r | |
88 | _Vdomessage(1, fmt, ap);\r | |
89 | va_end(ap);\r | |
90 | }\r | |
91 | \r | |
92 | void\r | |
93 | warnx(const char *fmt, ...)\r | |
94 | {\r | |
95 | va_list ap;\r | |
96 | va_start(ap, fmt);\r | |
97 | _Vdomessage(0, fmt, ap);\r | |
98 | va_end(ap);\r | |
99 | }\r |