fatal.c (580B)
1 /* Written by Kris Maglione <maglione.k at Gmail> */ 2 /* Public domain */ 3 #include <fmt.h> 4 #include "util.h" 5 6 typedef struct VFmt VFmt; 7 struct VFmt { 8 const char *fmt; 9 va_list args; 10 }; 11 12 #ifdef VARARGCK 13 # pragma varargck type "V" VFmt* 14 #endif 15 16 static int 17 Vfmt(Fmt *f) { 18 VFmt *vf; 19 int i; 20 21 vf = va_arg(f->args, VFmt*); 22 i = fmtvprint(f, vf->fmt, vf->args); 23 return i; 24 } 25 26 void 27 fatal(const char *fmt, ...) { 28 VFmt fp; 29 30 fmtinstall('V', Vfmt); 31 fmtinstall('', Vfmt); 32 33 fp.fmt = fmt; 34 va_start(fp.args, fmt); 35 fprint(2, "%s: fatal: %V\n", argv0, &fp); 36 va_end(fp.args); 37 38 exit(1); 39 }