aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
blob: e5398e950f32ab3cc05e32d6876bd1a959ce861d (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
#ifndef INCLUDED_UTILS_H
#define INCLUDED_UTILS_H

#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <stdio.h>

#define STRINGIFY(ARG) #ARG
#define TO_STRING(ARG) STRINGIFY (ARG)
#define LOG(PRIORITY, FMT, ...)                         \
  syslog (LOG_MAKEPRI (LOG_DAEMON, LOG_##PRIORITY),     \
          FMT __VA_OPT__ (,) __VA_ARGS__)
#define DEBUG( FMT, ...)                                                       \
  LOG (DEBUG, __FILE__ ":" TO_STRING (__LINE__) ": %s: " FMT, __func__ __VA_OPT__ (,) __VA_ARGS__)
#define EMERGENCY(FMT, ...) LOG (EMERG,   "emergency: " FMT __VA_OPT__ (,) __VA_ARGS__)
#define ALERT(    FMT, ...) LOG (ALERT,   "alert: "     FMT __VA_OPT__ (,) __VA_ARGS__)
#define CRITICAL( FMT, ...) LOG (CRIT,    "critical: "  FMT __VA_OPT__ (,) __VA_ARGS__)
#define ERROR(    FMT, ...) LOG (ERR,     "error: "     FMT __VA_OPT__ (,) __VA_ARGS__)
#define WARNING(  FMT, ...) LOG (WARNING, "warning: "   FMT __VA_OPT__ (,) __VA_ARGS__)
#define NOTICE(   FMT, ...) LOG (NOTICE,  "notice: "    FMT __VA_OPT__ (,) __VA_ARGS__)
#define INFO(     FMT, ...) LOG (INFO,    "info: "      FMT __VA_OPT__ (,) __VA_ARGS__)

#define UNUSED(X) ((void) (X))
#define UNREACHABLE() ASSERT (!"reached the unreachable...")

#define MALLOC malloc
#define REALLOC realloc
#define FREE free
#define ASSERT assert

#endif