change license from GPLv3 to GPLv3 or later
[mmq.git] / print.c
blob0b4a287feede94d328eb549c0df956c2ea96c232
1 #include "mmq.h"
3 /*
4 * not thread safe, we won't ever try to be
5 * this buffer is intentionally tiny because we want to keep all
6 * of our messages as short as possible. For path names, we write()
7 * to STDOUT_FILENO directly.
8 */
9 static char buf[80];
11 static void spew(int fd, const char *fmt, va_list ap)
13 int nr = vsnprintf(buf, sizeof(buf), fmt, ap);
15 assert(nr > 0 && nr < sizeof(buf) && "spew buffer too small");
16 write(fd, buf, nr);
19 void emit(const char *fmt, ...)
21 va_list ap;
23 va_start(ap, fmt);
24 spew(1, fmt, ap);
25 va_end(ap);
28 void warn(const char *fmt, ...)
30 va_list ap;
32 va_start(ap, fmt);
33 spew(2, fmt, ap);
34 va_end(ap);
37 NORETURN void die(const char *fmt, ...)
39 va_list ap;
41 va_start(ap, fmt);
42 spew(2, fmt, ap);
43 va_end(ap);
44 exit(1);