err.c (58f0484fa251c266ede97b591b499fe3dd4f578e) | err.c (3688be0eeb59367d9dd33e4b0963813b72ce0ef3) |
---|---|
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 --- 35 unchanged lines hidden (view full) --- 44#ifdef __STDC__ 45#include <stdarg.h> 46#else 47#include <varargs.h> 48#endif 49 50extern char *__progname; /* Program name, from crt0. */ 51 | 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 --- 35 unchanged lines hidden (view full) --- 44#ifdef __STDC__ 45#include <stdarg.h> 46#else 47#include <varargs.h> 48#endif 49 50extern char *__progname; /* Program name, from crt0. */ 51 |
52static FILE *err_file; /* file to use for error output */ 53static void (*err_exit)(int); 54 55void 56err_set_file(void *fp) 57{ 58 if (fp) 59 err_file = fp; 60 else 61 err_file = stderr; 62} 63 64void 65err_set_exit(void (*ef)(int)) 66{ 67 err_exit = ef; 68} 69 |
|
52__dead void 53#ifdef __STDC__ 54err(int eval, const char *fmt, ...) 55#else 56err(eval, fmt, va_alist) 57 int eval; 58 const char *fmt; 59 va_dcl --- 13 unchanged lines hidden (view full) --- 73verr(eval, fmt, ap) 74 int eval; 75 const char *fmt; 76 va_list ap; 77{ 78 int sverrno; 79 80 sverrno = errno; | 70__dead void 71#ifdef __STDC__ 72err(int eval, const char *fmt, ...) 73#else 74err(eval, fmt, va_alist) 75 int eval; 76 const char *fmt; 77 va_dcl --- 13 unchanged lines hidden (view full) --- 91verr(eval, fmt, ap) 92 int eval; 93 const char *fmt; 94 va_list ap; 95{ 96 int sverrno; 97 98 sverrno = errno; |
81 (void)fprintf(stderr, "%s: ", __progname); | 99 if (! err_file) 100 err_set_file((FILE *)0); 101 (void)fprintf(err_file, "%s: ", __progname); |
82 if (fmt != NULL) { | 102 if (fmt != NULL) { |
83 (void)vfprintf(stderr, fmt, ap); 84 (void)fprintf(stderr, ": "); | 103 (void)vfprintf(err_file, fmt, ap); 104 (void)fprintf(err_file, ": "); |
85 } | 105 } |
86 (void)fprintf(stderr, "%s\n", strerror(sverrno)); | 106 (void)fprintf(err_file, "%s\n", strerror(sverrno)); 107 if(err_exit) 108 err_exit(eval); |
87 exit(eval); 88} 89 90__dead void 91#if __STDC__ 92errx(int eval, const char *fmt, ...) 93#else 94errx(eval, fmt, va_alist) --- 13 unchanged lines hidden (view full) --- 108} 109 110__dead void 111verrx(eval, fmt, ap) 112 int eval; 113 const char *fmt; 114 va_list ap; 115{ | 109 exit(eval); 110} 111 112__dead void 113#if __STDC__ 114errx(int eval, const char *fmt, ...) 115#else 116errx(eval, fmt, va_alist) --- 13 unchanged lines hidden (view full) --- 130} 131 132__dead void 133verrx(eval, fmt, ap) 134 int eval; 135 const char *fmt; 136 va_list ap; 137{ |
116 (void)fprintf(stderr, "%s: ", __progname); | 138 if (! err_file) 139 err_set_file((FILE *)0); 140 (void)fprintf(err_file, "%s: ", __progname); |
117 if (fmt != NULL) | 141 if (fmt != NULL) |
118 (void)vfprintf(stderr, fmt, ap); 119 (void)fprintf(stderr, "\n"); | 142 (void)vfprintf(err_file, fmt, ap); 143 (void)fprintf(err_file, "\n"); 144 if (err_exit) 145 err_exit(eval); |
120 exit(eval); 121} 122 123void 124#if __STDC__ 125warn(const char *fmt, ...) 126#else 127warn(fmt, va_alist) --- 14 unchanged lines hidden (view full) --- 142void 143vwarn(fmt, ap) 144 const char *fmt; 145 va_list ap; 146{ 147 int sverrno; 148 149 sverrno = errno; | 146 exit(eval); 147} 148 149void 150#if __STDC__ 151warn(const char *fmt, ...) 152#else 153warn(fmt, va_alist) --- 14 unchanged lines hidden (view full) --- 168void 169vwarn(fmt, ap) 170 const char *fmt; 171 va_list ap; 172{ 173 int sverrno; 174 175 sverrno = errno; |
150 (void)fprintf(stderr, "%s: ", __progname); | 176 if (! err_file) 177 err_set_file((FILE *)0); 178 (void)fprintf(err_file, "%s: ", __progname); |
151 if (fmt != NULL) { | 179 if (fmt != NULL) { |
152 (void)vfprintf(stderr, fmt, ap); 153 (void)fprintf(stderr, ": "); | 180 (void)vfprintf(err_file, fmt, ap); 181 (void)fprintf(err_file, ": "); |
154 } | 182 } |
155 (void)fprintf(stderr, "%s\n", strerror(sverrno)); | 183 (void)fprintf(err_file, "%s\n", strerror(sverrno)); |
156} 157 158void 159#ifdef __STDC__ 160warnx(const char *fmt, ...) 161#else 162warnx(fmt, va_alist) 163 const char *fmt; --- 10 unchanged lines hidden (view full) --- 174 va_end(ap); 175} 176 177void 178vwarnx(fmt, ap) 179 const char *fmt; 180 va_list ap; 181{ | 184} 185 186void 187#ifdef __STDC__ 188warnx(const char *fmt, ...) 189#else 190warnx(fmt, va_alist) 191 const char *fmt; --- 10 unchanged lines hidden (view full) --- 202 va_end(ap); 203} 204 205void 206vwarnx(fmt, ap) 207 const char *fmt; 208 va_list ap; 209{ |
182 (void)fprintf(stderr, "%s: ", __progname); | 210 if (! err_file) 211 err_set_file((FILE *)0); 212 (void)fprintf(err_file, "%s: ", __progname); |
183 if (fmt != NULL) | 213 if (fmt != NULL) |
184 (void)vfprintf(stderr, fmt, ap); 185 (void)fprintf(stderr, "\n"); | 214 (void)vfprintf(err_file, fmt, ap); 215 (void)fprintf(err_file, "\n"); |
186} | 216} |