5 * Copyright 2003, 2004 Porchdog Software. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
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.
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.
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.
32 #include <salt/platform.h>
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
49 #if (defined( __GNUC__))
51 # if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
53 # define __C99_VA_ARGS__ 1
55 # define __GNU_VA_ARGS__ 0
59 # define __C99_VA_ARGS__ 0
61 # define __GNU_VA_ARGS__ 1
67 # define __C99_VA_ARGS__ 0
69 # define __GNU_VA_ARGS__ 0
74 # if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
76 # define __SW_FUNCTION__ __func__
78 #elif (defined( __GNUC__))
80 # define __SW_FUNCTION__ __PRETTY_FUNCTION__
82 #elif( defined(_MSC_VER ) && !defined(_WIN32_WCE))
84 # define __SW_FUNCTION__ __FUNCTION__
88 # define __SW_FUNCTION__ ""
93 #define sw_check(expr, label, action) \
106 #define sw_check_log(expr, label, action) \
111 sw_print_assert(0, NULL, __FILE__, __SW_FUNCTION__, __LINE__); \
120 #define sw_check_okay(code, label) \
123 if ((int) code != 0) \
130 #define sw_check_okay_log(code, label) \
133 if ((int) code != 0) \
135 sw_print_assert((int) code, NULL, __FILE__, __SW_FUNCTION__, __LINE__); \
141 #define sw_translate_error(expr, errno) ((expr) ? 0 : (errno))
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)
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
163 # define sw_assert(X) \
169 sw_print_assert( 0, #X, __FILE__, __SW_FUNCTION__, __LINE__); \
175 # define sw_assert(X)
183 sw_const_string assert_string,
184 sw_const_string file,
185 sw_const_string func,
194 sw_const_string format,
197 # if (__C99_VA_ARGS__)
199 # define sw_debug(...) sw_print_debug(__VA_ARGS__)
203 # define sw_debug sw_print_debug
209 # if (__C99_VA_ARGS__)
211 # define sw_debug(...)
215 # define sw_debug while( 0 )
222 #define SW_UNUSED_PARAM(X) (void) (X)
225 #if defined(__cplusplus)