Home | History | Annotate | Line # | Download | only in gen
err.c revision 1.10
      1 /*-
      2  * Copyright (c) 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #if defined(LIBC_SCCS) && !defined(lint)
     35 /* from: static char sccsid[] = "@(#)err.c	8.1 (Berkeley) 6/4/93"; */
     36 static char *rcsid = "$Id: err.c,v 1.10 1994/12/17 16:16:00 pk Exp $";
     37 #endif /* LIBC_SCCS and not lint */
     38 
     39 #include <err.h>
     40 #include <errno.h>
     41 #include <stdio.h>
     42 #include <stdlib.h>
     43 #include <string.h>
     44 
     45 #ifdef __STDC__
     46 #include <stdarg.h>
     47 #else
     48 #include <varargs.h>
     49 #endif
     50 
     51 extern char *__progname;		/* Program name, from crt0. */
     52 
     53 __dead void
     54 _verr(eval, fmt, ap)
     55 	int eval;
     56 	const char *fmt;
     57 	va_list ap;
     58 {
     59 	int sverrno;
     60 
     61 	sverrno = errno;
     62 	(void)fprintf(stderr, "%s: ", __progname);
     63 	if (fmt != NULL) {
     64 		(void)vfprintf(stderr, fmt, ap);
     65 		(void)fprintf(stderr, ": ");
     66 	}
     67 	(void)fprintf(stderr, "%s\n", strerror(sverrno));
     68 	exit(eval);
     69 }
     70 
     71 
     72 __dead void
     73 #ifdef __STDC__
     74 _err(int eval, const char *fmt, ...)
     75 #else
     76 _err(va_alist)
     77 	va_dcl
     78 #endif
     79 {
     80 	va_list ap;
     81 #if __STDC__
     82 	va_start(ap, fmt);
     83 #else
     84 	int eval;
     85 	const char *fmt;
     86 
     87 	va_start(ap);
     88 	eval = va_arg(ap, int);
     89 	fmt = va_arg(ap, const char *);
     90 #endif
     91 	_verr(eval, fmt, ap);
     92 	va_end(ap);
     93 }
     94 
     95 
     96 __dead void
     97 _verrx(eval, fmt, ap)
     98 	int eval;
     99 	const char *fmt;
    100 	va_list ap;
    101 {
    102 	(void)fprintf(stderr, "%s: ", __progname);
    103 	if (fmt != NULL)
    104 		(void)vfprintf(stderr, fmt, ap);
    105 	(void)fprintf(stderr, "\n");
    106 	exit(eval);
    107 }
    108 
    109 
    110 __dead void
    111 #if __STDC__
    112 _errx(int eval, const char *fmt, ...)
    113 #else
    114 _errx(va_alist)
    115 	va_dcl
    116 #endif
    117 {
    118 	va_list ap;
    119 #if __STDC__
    120 	va_start(ap, fmt);
    121 #else
    122 	int eval;
    123 	const char *fmt;
    124 
    125 	va_start(ap);
    126 	eval = va_arg(ap, int);
    127 	fmt = va_arg(ap, const char *);
    128 #endif
    129 	_verrx(eval, fmt, ap);
    130 	va_end(ap);
    131 }
    132 
    133 
    134 void
    135 _vwarn(fmt, ap)
    136 	const char *fmt;
    137 	va_list ap;
    138 {
    139 	int sverrno;
    140 
    141 	sverrno = errno;
    142 	(void)fprintf(stderr, "%s: ", __progname);
    143 	if (fmt != NULL) {
    144 		(void)vfprintf(stderr, fmt, ap);
    145 		(void)fprintf(stderr, ": ");
    146 	}
    147 	(void)fprintf(stderr, "%s\n", strerror(sverrno));
    148 }
    149 
    150 
    151 void
    152 #if __STDC__
    153 _warn(const char *fmt, ...)
    154 #else
    155 _warn(va_alist)
    156 	va_dcl
    157 #endif
    158 {
    159 	va_list ap;
    160 #if __STDC__
    161 	va_start(ap, fmt);
    162 #else
    163 	const char *fmt;
    164 
    165 	va_start(ap);
    166 	fmt = va_arg(ap, const char *);
    167 #endif
    168 	_vwarn(fmt, ap);
    169 	va_end(ap);
    170 }
    171 
    172 
    173 void
    174 _vwarnx(fmt, ap)
    175 	const char *fmt;
    176 	va_list ap;
    177 {
    178 	(void)fprintf(stderr, "%s: ", __progname);
    179 	if (fmt != NULL)
    180 		(void)vfprintf(stderr, fmt, ap);
    181 	(void)fprintf(stderr, "\n");
    182 }
    183 
    184 
    185 void
    186 #ifdef __STDC__
    187 _warnx(const char *fmt, ...)
    188 #else
    189 _warnx(va_alist)
    190 	va_dcl
    191 #endif
    192 {
    193 	va_list ap;
    194 #ifdef __STDC__
    195 	va_start(ap, fmt);
    196 #else
    197 	const char *fmt;
    198 
    199 	va_start(ap);
    200 	fmt = va_arg(ap, const char *);
    201 #endif
    202 	_vwarnx(fmt, ap);
    203 	va_end(ap);
    204 }
    205