skiplist/x.c

55 lines
797 B
C
Raw Permalink Normal View History

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