1 /*- 2 * Copyright (c) 1993 The Regents of the University of California. 3 * 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 /*static char sccsid[] = "from: @(#)err.c 5.2 (Berkeley) 3/19/93";*/ 36 static char rcsid[] = "$Id: err.c,v 1.3 1993/07/30 08:22:07 mycroft 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 volatile void 54 #ifdef __STDC__ 55 err(int eval, const char *fmt, ...) 56 #else 57 err(eval, fmt, va_alist) 58 int eval; 59 const char *fmt; 60 va_dcl 61 #endif 62 { 63 _VA_LIST_ ap; 64 #if __STDC__ 65 va_start(ap, fmt); 66 #else 67 va_start(ap); 68 #endif 69 verr(eval, fmt, ap); 70 va_end(ap); 71 } 72 73 volatile void 74 verr(eval, fmt, ap) 75 int eval; 76 const char *fmt; 77 _VA_LIST_ ap; 78 { 79 int sverrno; 80 81 sverrno = errno; 82 (void)fprintf(stderr, "%s: ", __progname); 83 if (fmt != NULL) { 84 (void)vfprintf(stderr, fmt, ap); 85 (void)fprintf(stderr, ": "); 86 } 87 (void)fprintf(stderr, "%s\n", strerror(sverrno)); 88 exit(eval); 89 } 90 91 volatile void 92 #if __STDC__ 93 errx(int eval, const char *fmt, ...) 94 #else 95 errx(eval, fmt, va_alist) 96 int eval; 97 const char *fmt; 98 va_dcl 99 #endif 100 { 101 _VA_LIST_ ap; 102 #if __STDC__ 103 va_start(ap, fmt); 104 #else 105 va_start(ap); 106 #endif 107 verrx(eval, fmt, ap); 108 va_end(ap); 109 } 110 111 volatile void 112 verrx(eval, fmt, ap) 113 int eval; 114 const char *fmt; 115 _VA_LIST_ ap; 116 { 117 (void)fprintf(stderr, "%s: ", __progname); 118 if (fmt != NULL) 119 (void)vfprintf(stderr, fmt, ap); 120 (void)fprintf(stderr, "\n"); 121 exit(eval); 122 } 123 124 void 125 #if __STDC__ 126 warn(const char *fmt, ...) 127 #else 128 warn(fmt, va_alist) 129 int eval; 130 const char *fmt; 131 va_dcl 132 #endif 133 { 134 _VA_LIST_ ap; 135 #if __STDC__ 136 va_start(ap, fmt); 137 #else 138 va_start(ap); 139 #endif 140 vwarn(fmt, ap); 141 va_end(ap); 142 } 143 144 void 145 vwarn(fmt, ap) 146 const char *fmt; 147 _VA_LIST_ ap; 148 { 149 int sverrno; 150 151 sverrno = errno; 152 (void)fprintf(stderr, "%s: ", __progname); 153 if (fmt != NULL) { 154 (void)vfprintf(stderr, fmt, ap); 155 (void)fprintf(stderr, ": "); 156 } 157 (void)fprintf(stderr, "%s\n", strerror(sverrno)); 158 } 159 160 void 161 #ifdef __STDC__ 162 warnx(const char *fmt, ...) 163 #else 164 warnx(fmt, va_alist) 165 int eval; 166 const char *fmt; 167 va_dcl 168 #endif 169 { 170 _VA_LIST_ ap; 171 #ifdef __STDC__ 172 va_start(ap, fmt); 173 #else 174 va_start(ap); 175 #endif 176 vwarnx(fmt, ap); 177 va_end(ap); 178 } 179 180 void 181 vwarnx(fmt, ap) 182 const char *fmt; 183 _VA_LIST_ ap; 184 { 185 (void)fprintf(stderr, "%s: ", __progname); 186 if (fmt != NULL) 187 (void)vfprintf(stderr, fmt, ap); 188 (void)fprintf(stderr, "\n"); 189 } 190