Debian Codegraph @

avahi-compat-howl/include/salt/debug.h

raw
1 #ifndef _salt_debug_h
2 #define _salt_debug_h
3
4 /*
5 * Copyright 2003, 2004 Porchdog Software. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * The views and conclusions contained in the software and documentation are those
28 * of the authors and should not be interpreted as representing official policies,
29 * either expressed or implied, of Porchdog Software.
30 */
31
32 #include <salt/platform.h>
33 #include <stdarg.h>
34
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41
42 #define SW_LOG_WARNING 1 << 0
43 #define SW_LOG_ERROR 1 << 1
44 #define SW_LOG_NOTICE 1 << 2
45 #define SW_LOG_VERBOSE 1 << 3
46 #define SW_LOG_OFF 0x0
47
48
49 #if (defined( __GNUC__))
50
51 # if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
52
53 # define __C99_VA_ARGS__ 1
54
55 # define __GNU_VA_ARGS__ 0
56
57 # else
58
59 # define __C99_VA_ARGS__ 0
60
61 # define __GNU_VA_ARGS__ 1
62
63 # endif
64
65 #else
66
67 # define __C99_VA_ARGS__ 0
68
69 # define __GNU_VA_ARGS__ 0
70
71 #endif
72
73
74 # if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
75
76 # define __SW_FUNCTION__ __func__
77
78 #elif (defined( __GNUC__))
79
80 # define __SW_FUNCTION__ __PRETTY_FUNCTION__
81
82 #elif( defined(_MSC_VER ) && !defined(_WIN32_WCE))
83
84 # define __SW_FUNCTION__ __FUNCTION__
85
86 #else
87
88 # define __SW_FUNCTION__ ""
89
90 #endif
91
92
93 #define sw_check(expr, label, action) \
94 do \
95 { \
96 if (!(expr)) \
97 { \
98 { \
99 action; \
100 } \
101 goto label; \
102 } \
103 } while (0)
104
105
106 #define sw_check_log(expr, label, action) \
107 do \
108 { \
109 if (!(expr)) \
110 { \
111 sw_print_assert(0, NULL, __FILE__, __SW_FUNCTION__, __LINE__); \
112 { \
113 action; \
114 } \
115 goto label; \
116 } \
117 } while (0)
118
119
120 #define sw_check_okay(code, label) \
121 do \
122 { \
123 if ((int) code != 0) \
124 { \
125 goto label; \
126 } \
127 } while (0)
128
129
130 #define sw_check_okay_log(code, label) \
131 do \
132 { \
133 if ((int) code != 0) \
134 { \
135 sw_print_assert((int) code, NULL, __FILE__, __SW_FUNCTION__, __LINE__); \
136 goto label; \
137 } \
138 } while ( 0 )
139
140
141 #define sw_translate_error(expr, errno) ((expr) ? 0 : (errno))
142
143
144 #if defined(WIN32)
145
146 # define sw_socket_errno() (int) WSAGetLastError()
147 # define sw_set_socket_errno(X) WSASetLastError(X)
148 # define sw_system_errno() (int) GetLastError()
149 # define sw_set_system_errno(X) SetLastError(X)
150
151 #else
152
153 # define sw_socket_errno() errno
154 # define sw_set_socket_errno(X) errno = X
155 # define sw_system_errno() errno
156 # define sw_set_system_errno(X) errno = X
157
158 #endif
159
160
161 #if !defined(NDEBUG)
162
163 # define sw_assert(X) \
164 \
165 do \
166 { \
167 if (!(X)) \
168 { \
169 sw_print_assert( 0, #X, __FILE__, __SW_FUNCTION__, __LINE__); \
170 } \
171 } while( 0 )
172
173 #else
174
175 # define sw_assert(X)
176
177 #endif
178
179
180 void HOWL_API
181 sw_print_assert(
182 int code,
183 sw_const_string assert_string,
184 sw_const_string file,
185 sw_const_string func,
186 int line);
187
188
189 #if !defined(NDEBUG)
190
191 void HOWL_API
192 sw_print_debug(
193 int level,
194 sw_const_string format,
195 ...);
196
197 # if (__C99_VA_ARGS__)
198
199 # define sw_debug(...) sw_print_debug(__VA_ARGS__)
200
201 # else
202
203 # define sw_debug sw_print_debug
204
205 # endif
206
207 #else
208
209 # if (__C99_VA_ARGS__)
210
211 # define sw_debug(...)
212
213 # else
214
215 # define sw_debug while( 0 )
216
217 # endif
218
219 #endif
220
221
222 #define SW_UNUSED_PARAM(X) (void) (X)
223
224
225 #if defined(__cplusplus)
226 }
227 #endif
228
229
230 #endif