#include "x.h" extern int dodebug; static void _log_stderr(FILE *f, const char *fmt, va_list ap) { char buf[MAXLINE]; vsnprintf(buf, MAXLINE-1, fmt, ap); fflush(f); fputs(buf, f); fflush(f); } void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); _log_stderr(stderr, fmt, ap); va_end(ap); exit(1); } void debug(const char *fmt, ...) { va_list ap; if (dodebug) { va_start(ap, fmt); _log_stderr(stderr, fmt, ap); va_end(ap); } } void print(const char *fmt, ...) { va_list ap; va_start(ap, fmt); _log_stderr(stdout, fmt, ap); va_end(ap); } void *xmalloc(size_t size) { void *foo = malloc(size); if (foo == NULL) { fatal("Not enough memory\n"); } return foo; }