3 * general utility functions
14 static void vdie_vprintf(const char *fmt, va_list al) {
17 vfprintf(stderr,fmt,al_copy);
18 die_vprintf_hook(fmt,al);
21 static void vdie_printf(const char *fmt, ...) {
28 void vdie(const char *fmt, int ev, va_list al) {
29 vdie_printf("%s: fatal: ", progname);
31 if (ev) vdie_printf(": %s",strerror(ev));
37 void badusage(const char *why) {
38 fprintf(stderr,"%s: bad usage: %s\n",progname,why); exit(8);
41 void die(const char *fmt, ...)
42 { va_list al; va_start(al,fmt); vdie(fmt,0,al); }
43 void diee(const char *fmt, ...)
44 { va_list al; va_start(al,fmt); vdie(fmt,errno,al); }
46 { diee("malloc failed"); }
48 void *mmalloc(size_t sz) {
56 void *mrealloc(void *o, size_t sz) {
58 if (!sz) { free(o); return 0; }
64 char *mstrdupl(const char *s, int l) {
72 char *mstrdup(const char *s) { return mstrdupl(s,strlen(s)); }
74 void mgettimeofday(struct timeval *tv) {
76 r= gettimeofday(tv,0);
77 if (r) diee("gettimeofday failed");