You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
797 B
54 lines
797 B
#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; |
|
} |
|
|
|
|