1/* 2 * @(#)err 5.1 (Berkeley) 06/29/91 3 * 4 * Error routines can be tricky. The following works in most cases, 5 * and can be easily adapted per program. It allows both: 6 * 7 * if ((fp = fopen(file, "r")) == NULL) 8 * err("%s: %s", file, strerror(errno)); 9 * and: 10 * if ((p = malloc(sizeof(int))) == NULL) 11 * err("%s", strerror(errno)); 12 * 13 * Never use perror(3). 14 */ 15#if __STDC__ 16#include <stdarg.h> 17#else 18#include <varargs.h> 19#endif 20 21void 22#if __STDC__ 23err(const char *fmt, ...) 24#else 25err(fmt, va_alist) 26 char *fmt; 27 va_dcl 28#endif 29{ 30 va_list ap; 31#if __STDC__ 32 va_start(ap, fmt); 33#else 34 va_start(ap); 35#endif 36 (void)fprintf(stderr, "program: "); 37 (void)vfprintf(stderr, fmt, ap); 38 va_end(ap); 39 (void)fprintf(stderr, "\n"); 40 exit(1); 41 /* NOTREACHED */ 42} 43