7 #define LOG_DEFAULT LOG_INFO
19 /* Helper functions */
20 static void message(int level, const char *prefix, const char *fmt, va_list ap)
22 if (level >= LOG_DEFAULT-loglevel) {
23 fprintf(stderr, "%s: ", prefix);
24 vfprintf(stderr, fmt, ap);
25 fprintf(stderr, "\n");
29 /* Mesage functions */
30 void debug(const char *fmt, ...)
34 message(LOG_DEBUG, "debug", fmt, ap);
38 void info(const char *fmt, ...)
42 message(LOG_INFO, "info", fmt, ap);
46 void warn(const char *fmt, ...)
50 message(LOG_WARN, "warning", fmt, ap);
54 void error(const char *fmt, ...)
58 message(LOG_ERROR, "error", fmt, ap);
64 void hexdump(const char *label, const char *prefix,
65 const uint8_t *data, int len, ...)
70 if (!label) label = "";
71 if (!prefix) prefix = "%04x: ";
74 for (int i = 0; i < len; i++) {
78 } else if ((i % 8) == 0) {
80 } else if ((i % 2) == 0) {
83 printf("%02hhx", data[i]);
92 void *alloc0(int size)
94 void *out = calloc(1, size);
96 error("Alloc failed");