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