aboutsummaryrefslogtreecommitdiffstats
path: root/log.h
blob: 6fb0326252ba0498ee31ffe604f2937f9fe040b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef LOG_H_
#define LOG_H_

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LOG(fmt, ...) do {                                              \
    char buf[999];                                                      \
    sprintf(buf, fmt, __VA_ARGS__);                                     \
    fprintf(stderr, "*kati*: %s\n", buf);                               \
  } while(0)

#define PERROR(...) do {                                        \
    char buf[999];                                              \
    sprintf(buf, __VA_ARGS__);                                  \
    fprintf(stderr, "%s: %s\n", buf, strerror(errno));          \
    exit(1);                                                    \
  } while (0)

#define ERROR(...) do {                                         \
    char buf[999];                                              \
    sprintf(buf, __VA_ARGS__);                                  \
    fprintf(stderr, "%s\n", buf);                               \
    exit(1);                                                    \
  } while (0)

#define CHECK(c) if (!(c)) ERROR("%s:%d: %s", __FILE__, __LINE__, #c)

#endif  // LOG_H_