libsir 2.2.5
Standard Incident Reporter
Loading...
Searching...
No Matches
errors.h
1/*
2 * errors.h
3 *
4 * Version: 2.2.5
5 *
6 * -----------------------------------------------------------------------------
7 *
8 * SPDX-License-Identifier: MIT
9 *
10 * Copyright (c) 2018-2024 Ryan M. Lederman <lederman@gmail.com>
11 * Copyright (c) 2018-2024 Jeffrey H. Johnson <trnsz@pobox.com>
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy of
14 * this software and associated documentation files (the "Software"), to deal in
15 * the Software without restriction, including without limitation the rights to
16 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17 * the Software, and to permit persons to whom the Software is furnished to do so,
18 * subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in all
21 * copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 *
30 * -----------------------------------------------------------------------------
31 */
32
33#ifndef _SIR_ERRORS_H_INCLUDED
34# define _SIR_ERRORS_H_INCLUDED
35
36# include "sir/types.h"
37
70
73# if defined(__cplusplus)
74extern "C" {
75# endif
76
79# define _sir_mkerror(code) (((uint32_t)((code) & 0x7fffffffU) << 16) | 0x80000000U)
80
82static inline
83bool _sir_validerror(uint32_t err) {
84 uint32_t masked = err & 0x8fffffffU;
85 return masked >= 0x80000000U && masked <= 0x8fff0000U;
86}
87
89static inline
90uint16_t _sir_geterrcode(uint32_t err) {
91 return (err >> 16) & 0x7fffU;
92}
93
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
120bool __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
123void __sir_setoserror(int code, const char* msg, const char* func,
124 const char* file, uint32_t line);
125
127bool __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__)
131void _sir_invalidparameter(const wchar_t* expr, const wchar_t* func, const wchar_t* file,
132 unsigned int line, uintptr_t reserved);
133
134bool __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
140uint32_t _sir_geterror(char message[SIR_MAXERROR]);
141
143void _sir_geterrorinfo(sir_errorinfo* err);
144
146void _sir_reset_tls_error(void);
147
148# if defined(SIR_SELFLOG)
150PRINTF_FORMAT_ATTR(4, 5)
151void __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
154static inline
155void __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 /* !_SIR_ERRORS_H_INCLUDED */
#define SIR_MAXERROR
The maximum size, in characters, of an error message.
Definition config.h:419
sir_errorcode
Error codes.
Definition errors.h:44
@ SIR_E_STRING
Invalid string argument.
Definition errors.h:54
@ SIR_E_TEXTCOLOR
Text color is invalid for mode.
Definition errors.h:62
@ SIR_E_PLATFORM
Platform error code %d: %s.
Definition errors.h:67
@ SIR_E_DUPITEM
Item already managed by libsir.
Definition errors.h:48
@ SIR_E_INTERNAL
An internal error has occurred.
Definition errors.h:59
@ SIR_E_UNAVAIL
Feature is disabled or unavailable.
Definition errors.h:58
@ SIR_E_TEXTSTYLE
Text style is invalid.
Definition errors.h:53
@ SIR_E_OPTIONS
Option flags are invalid.
Definition errors.h:51
@ SIR_E_NOITEM
Item not managed by libsir.
Definition errors.h:49
@ SIR_E_PLUGINVER
Plugin interface version unsupported.
Definition errors.h:65
@ SIR_E_UNKNOWN
Unknown error.
Definition errors.h:68
@ SIR_E_PLUGINDAT
Data produced by plugin is invalid.
Definition errors.h:64
@ SIR_E_NOTREADY
libsir has not been initialized
Definition errors.h:46
@ SIR_E_NULLPTR
NULL pointer argument.
Definition errors.h:55
@ SIR_E_LEVELS
Level flags are invalid.
Definition errors.h:52
@ SIR_E_ALREADY
libsir is already initialized
Definition errors.h:47
@ SIR_E_PLUGINERR
Plugin reported failure.
Definition errors.h:66
@ SIR_E_COLORMODE
Color mode is invalid.
Definition errors.h:60
@ SIR_E_PLUGINBAD
Plugin module is malformed.
Definition errors.h:63
@ SIR_E_INVALID
Invalid argument.
Definition errors.h:56
@ SIR_E_NODEST
No destinations registered for level.
Definition errors.h:57
@ SIR_E_NOROOM
Maximum number of items already stored.
Definition errors.h:50
@ SIR_E_NOERROR
The operation completed successfully.
Definition errors.h:45
@ SIR_E_TEXTATTR
Text attributes are invalid.
Definition errors.h:61
Information about an error that occurred.
Definition types.h:150