Debian Codegraph @

include/toolerror.h

raw symbols SCIP
1 // ****************************************************************************
2 // Project: libguytools
3 // ****************************************************************************
4 // Programmer: Guy Voncken
5 // Police Grand-Ducale
6 // Service de Police Judiciaire
7 // Section Nouvelles Technologies
8 // ****************************************************************************
9 // Module: Error handling
10 // ****************************************************************************
11
12 // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
13 // 2018, 2019
14 // Guy Voncken
15 //
16 // This file is part of libguytools.
17 //
18 // libguytools is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // libguytools is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with libguytools. If not, see <http://www.gnu.org/licenses/>.
30
31 #ifndef __TOOLERROR_H__
32 #define __TOOLERROR_H__
33
34 #ifndef __FFL__
35 #define __FFL__ __FILE__, __FUNCTION__, __LINE__
36 #endif
37
38 // -----------
39 // Constants
40 // -----------
41
42 #define NO_ERROR 0
43
44 // ---------------------------------------
45 // Macros for comfortable error checking
46 // ---------------------------------------
47
48 #define CHK(Func) \
49 /*lint -save -e506 -e774*/ /*Warning 506: Constant value Boolean; Info 774: Boolean within 'if' always evaluates to True */ \
50 { \
51 APIRET ec; \
52 if ((ec = Func) != NO_ERROR) \
53 { \
54 (void)ToolErrorCheck (__FFL__, ec); \
55 return ec; \
56 } \
57 } \
58 /*lint -restore*/
59
60
61 #define CHK_CONST(ec) \
62 { \
63 (void)ToolErrorCheck (__FFL__, ec); \
64 return ec; \
65 } \
66
67
68 #define CHK_RET(Func) \
69 { \
70 APIRET ec; \
71 if ((ec = Func) != NO_ERROR) \
72 return ec; \
73 }
74
75
76 #define CHK_NORET(Func) \
77 { \
78 APIRET ec; \
79 if ((ec = Func) != NO_ERROR) \
80 (void)ToolErrorCheck (__FFL__, ec); \
81 }
82
83
84
85 #define TOOL_CHK(Fn) \
86 { \
87 APIRET ec; \
88 if ((ec=Fn) != NO_ERROR) \
89 return ec; \
90 }
91
92 // ------------------
93 // Type definitions
94 // ------------------
95
96 typedef int APIRET;
97 typedef int * pAPIRET;
98
99 // -----------------------------
100 // ToolError's own error codes
101 // -----------------------------
102
103 enum
104 {
105 TOOL_ERROR_ENTRY_NOT_FOUND = ERROR_BASE_TOOL_ERROR + 1,
106 TOOL_ERROR_DUPLICATE_ENTRY ,
107 TOOL_ERROR_NOT_INITIALISED ,
108 TOOL_ERROR_ALREADY_INITIALISED
109 };
110
111 // -------------------------------
112 // Prototypes and wrapper macros
113 // -------------------------------
114
115 typedef void (* t_pToolErrorLogFn)(const char *pFileName, const char *pFunctionName, int LineNr, const char *pFormat, va_list pArguments);
116
117 APIRET ToolErrorSetLogFn (t_pToolErrorLogFn pLogFn);
118 APIRET ToolErrorRegisterError (int ErrorCode, const char *pErrorMsg);
119 APIRET ToolErrorGetMessage (int ErrorCode, const char **ppMessage);
120 const char *ToolErrorMessage (int ErrorCode);
121 const char *ToolErrorTranslateErrno (int Errno);
122
123
124 APIRET ToolErrorInit (unsigned int MaxErrors);
125 APIRET ToolErrorDeInit (void);
126
127 APIRET ToolErrorCheck (char const *pFileName, char const *pFunctionName, int LineNr, APIRET ErrorCode);
128 APIRET ToolErrorLog (char const *pFileName, char const *pFunctionName, int LineNr, const char * pFormat, ...) __attribute__ ((format (printf, 4, 5)));
129
130 #define TOOL_ERROR_REGISTER_CODE(ErrorCode) ToolErrorRegisterError(ErrorCode, #ErrorCode)
131
132 #endif
133