aboutsummaryrefslogtreecommitdiffstats
path: root/log.h
blob: 847adabc12d7bd0ea82ab02aa3159c47966d3d21 (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
32
33
34
35
36
37
#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 WARN(...) do {                                          \
    char buf[999];                                              \
    sprintf(buf, __VA_ARGS__);                                  \
    fprintf(stderr, "%s\n", buf);                               \
  } 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_