This source file includes following definitions.
- _sir_validerror
- _sir_geterrcode
- __sir_fakefunc
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 #ifndef _SIR_ERRORS_H_INCLUDED
34 # define _SIR_ERRORS_H_INCLUDED
35
36 # include "sir/types.h"
37
38
39
40
41
42
43
44 enum sir_errorcode {
45 SIR_E_NOERROR = 1,
46 SIR_E_NOTREADY = 2,
47 SIR_E_ALREADY = 3,
48 SIR_E_DUPITEM = 4,
49 SIR_E_NOITEM = 5,
50 SIR_E_NOROOM = 6,
51 SIR_E_OPTIONS = 7,
52 SIR_E_LEVELS = 8,
53 SIR_E_TEXTSTYLE = 9,
54 SIR_E_STRING = 10,
55 SIR_E_NULLPTR = 11,
56 SIR_E_INVALID = 12,
57 SIR_E_NODEST = 13,
58 SIR_E_UNAVAIL = 14,
59 SIR_E_INTERNAL = 15,
60 SIR_E_COLORMODE = 16,
61 SIR_E_TEXTATTR = 17,
62 SIR_E_TEXTCOLOR = 18,
63 SIR_E_PLUGINBAD = 19,
64 SIR_E_PLUGINDAT = 20,
65 SIR_E_PLUGINVER = 21,
66 SIR_E_PLUGINERR = 22,
67 SIR_E_PLATFORM = 23,
68 SIR_E_UNKNOWN = 4095,
69 };
70
71
72
73 # if defined(__cplusplus)
74 extern "C" {
75 # endif
76
77
78
79 # define _sir_mkerror(code) (((uint32_t)((code) & 0x7fffffffU) << 16) | 0x80000000U)
80
81
82 static inline
83 bool _sir_validerror(uint32_t err) {
84 uint32_t masked = err & 0x8fffffffU;
85 return masked >= 0x80000000U && masked <= 0x8fff0000U;
86 }
87
88
89 static inline
90 uint16_t _sir_geterrcode(uint32_t err) {
91 return (err >> 16) & 0x7fffU;
92 }
93
94
95 # define _SIR_E_NOERROR _sir_mkerror(SIR_E_NOERROR)
96 # define _SIR_E_NOTREADY _sir_mkerror(SIR_E_NOTREADY)
97 # define _SIR_E_ALREADY _sir_mkerror(SIR_E_ALREADY)
98 # define _SIR_E_DUPITEM _sir_mkerror(SIR_E_DUPITEM)
99 # define _SIR_E_NOITEM _sir_mkerror(SIR_E_NOITEM)
100 # define _SIR_E_NOROOM _sir_mkerror(SIR_E_NOROOM)
101 # define _SIR_E_OPTIONS _sir_mkerror(SIR_E_OPTIONS)
102 # define _SIR_E_LEVELS _sir_mkerror(SIR_E_LEVELS)
103 # define _SIR_E_TEXTSTYLE _sir_mkerror(SIR_E_TEXTSTYLE)
104 # define _SIR_E_STRING _sir_mkerror(SIR_E_STRING)
105 # define _SIR_E_NULLPTR _sir_mkerror(SIR_E_NULLPTR)
106 # define _SIR_E_INVALID _sir_mkerror(SIR_E_INVALID)
107 # define _SIR_E_NODEST _sir_mkerror(SIR_E_NODEST)
108 # define _SIR_E_UNAVAIL _sir_mkerror(SIR_E_UNAVAIL)
109 # define _SIR_E_INTERNAL _sir_mkerror(SIR_E_INTERNAL)
110 # define _SIR_E_COLORMODE _sir_mkerror(SIR_E_COLORMODE)
111 # define _SIR_E_TEXTATTR _sir_mkerror(SIR_E_TEXTATTR)
112 # define _SIR_E_TEXTCOLOR _sir_mkerror(SIR_E_TEXTCOLOR)
113 # define _SIR_E_PLUGINBAD _sir_mkerror(SIR_E_PLUGINBAD)
114 # define _SIR_E_PLUGINDAT _sir_mkerror(SIR_E_PLUGINDAT)
115 # define _SIR_E_PLUGINVER _sir_mkerror(SIR_E_PLUGINVER)
116 # define _SIR_E_PLUGINERR _sir_mkerror(SIR_E_PLUGINERR)
117 # define _SIR_E_PLATFORM _sir_mkerror(SIR_E_PLATFORM)
118 # define _SIR_E_UNKNOWN _sir_mkerror(SIR_E_UNKNOWN)
119
120 bool __sir_seterror(uint32_t err, const char* func, const char* file, uint32_t line);
121 # define _sir_seterror(err) __sir_seterror(err, __func__, __file__, __LINE__)
122
123 void __sir_setoserror(int code, const char* msg, const char* func,
124 const char* file, uint32_t line);
125
126
127 bool __sir_handleerr(int code, const char* func, const char* file, uint32_t line);
128 # define _sir_handleerr(code) __sir_handleerr(code, __func__, __file__, __LINE__)
129
130 # if defined(__WIN__)
131 void _sir_invalidparameter(const wchar_t* expr, const wchar_t* func, const wchar_t* file,
132 unsigned int line, uintptr_t reserved);
133
134 bool __sir_handlewin32err(DWORD code, const char* func, const char* file, uint32_t line);
135 # define _sir_handlewin32err(code) __sir_handlewin32err((DWORD)code, __func__, __file__, __LINE__)
136 # endif
137
138
139
140 uint32_t _sir_geterror(char message[SIR_MAXERROR]);
141
142
143 void _sir_geterrorinfo(sir_errorinfo* err);
144
145
146 void _sir_reset_tls_error(void);
147
148 # if defined(SIR_SELFLOG)
149
150 PRINTF_FORMAT_ATTR(4, 5)
151 void __sir_selflog(const char* func, const char* file, uint32_t line, PRINTF_FORMAT const char* format, ...);
152 # define _sir_selflog(...) __sir_selflog(__func__, __file__, __LINE__, __VA_ARGS__)
153 # else
154 static inline
155 void __sir_fakefunc(const char* format, ...) { (void)format; }
156 # define _sir_selflog(...) __sir_fakefunc(__VA_ARGS__)
157 # endif
158
159 # if defined(__cplusplus)
160 }
161 # endif
162
163 #endif