forked from znort987/blockparser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errlog.h
108 lines (93 loc) · 2.06 KB
/
errlog.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef __ERRLOG_H__
#define __ERRLOG_H__
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
static inline void vError(
int level,
bool system,
const char *format,
va_list vaList
)
{
fflush(stdout);
fflush(stderr);
bool info = (level==3);
bool fatal = (level==0);
bool warning = (level==2);
const char *msgType =
info ? "info" :
fatal ? "fatal" :
warning ? "warning" :
"error"
;
fprintf(
stderr,
"%s: %s%s",
msgType,
system ? strerror(errno) : "",
system ? ": " : ""
);
vfprintf(
stderr,
format,
vaList
);
fputc('\n', stderr);
fflush(stdout);
fflush(stderr);
if(fatal) abort();
}
static inline void sysErr(
const char *format,
...
)
{
va_list vaList;
va_start(vaList, format);
vError(1, true, format, vaList);
va_end(vaList);
}
static inline void errFatal(
const char *format,
...
)
{
va_list vaList;
va_start(vaList, format);
vError(0, false, format, vaList);
va_end(vaList);
}
static inline void sysErrFatal(
const char *format,
...
)
{
va_list vaList;
va_start(vaList, format);
vError(0, true, format, vaList);
va_end(vaList);
}
static inline void warning(
const char *format,
...
)
{
va_list vaList;
va_start(vaList, format);
vError(2, false, format, vaList);
va_end(vaList);
}
static inline void info(
const char *format,
...
)
{
va_list vaList;
va_start(vaList, format);
vError(3, false, format, vaList);
va_end(vaList);
}
#endif // __ERRLOG_H__