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