commit f5da49e266448417729a9032e719bd52eea51548
parent 460ac864a17b1dd7953c86bcc3ac0ee9acbb079d
Author: Kris Maglione <jg@suckless.org>
Date: Mon, 16 Jul 2007 22:16:58 -0400
Make fatal() a bit nicer.
Diffstat:
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/cmd/util.c b/cmd/util.c
@@ -9,30 +9,37 @@
#include <util.h>
#include <fmt.h>
+typedef struct VFmt VFmt;
+struct VFmt {
+ const char *fmt;
+ va_list args;
+};
+
+#ifdef VARARGCK
+# pragma varargck type "V" VFmt*
+#endif
+
static int
Vfmt(Fmt *f) {
- char *fmt;
- va_list ap;
+ VFmt *vf;
int i;
- fmt = va_arg(f->args, char*);
- va_copy(ap, va_arg(f->args, va_list));
-
- i = fmtvprint(f, fmt, ap);
- va_end(ap);
+ vf = va_arg(f->args, VFmt*);
+ i = fmtvprint(f, vf->fmt, vf->args);
return i;
}
void
fatal(const char *fmt, ...) {
- va_list ap;
+ VFmt fp;
fmtinstall('V', Vfmt);
fmtinstall('\001', Vfmt);
- va_start(ap, fmt);
- fprint(2, "%s: fatal: %V\n", argv0, fmt, ap);
- va_end(ap);
+ fp.fmt = fmt;
+ va_start(fp.args, fmt);
+ fprint(2, "%s: fatal: %V\n", argv0, &fp);
+ va_end(fp.args);
exit(1);
}