2 * Copyright (c) 2004, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _SUDO_ERROR_H_
18 #define _SUDO_ERROR_H_
23 * We wrap error/errorx and warn/warnx so that the same output can
24 * go to the debug file, if there is one.
26 #if defined(SUDO_ERROR_WRAP) && SUDO_ERROR_WRAP == 0
27 # if defined(__GNUC__) && __GNUC__ == 2
28 # define error(rval, fmt...) error2((rval), fmt)
29 # define errorx(rval, fmt...) errorx2((rval), fmt)
30 # define warning(fmt...) warning2(fmt)
31 # define warningx(fmt...) warningx2(fmt)
33 # define error(rval, ...) error2((rval), __VA_ARGS__)
34 # define errorx(rval, ...) errorx2((rval), __VA_ARGS__)
35 # define warning(...) warning2(__VA_ARGS__)
36 # define warningx(...) warningx2(__VA_ARGS__)
37 # endif /* __GNUC__ == 2 */
38 #else /* SUDO_ERROR_WRAP */
39 # if defined(__GNUC__) && __GNUC__ == 2
40 # define error(rval, fmt...) do { \
41 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
42 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
44 error2((rval), fmt); \
46 # define errorx(rval, fmt...) do { \
47 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
48 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt); \
49 errorx2((rval), fmt); \
51 # define warning(fmt...) do { \
52 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
53 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
57 # define warningx(fmt...) do { \
58 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
59 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt); \
63 # define error(rval, ...) do { \
64 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
65 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
67 error2((rval), __VA_ARGS__); \
69 # define errorx(rval, ...) do { \
70 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
71 SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, __VA_ARGS__); \
72 errorx2((rval), __VA_ARGS__); \
74 # define warning(...) do { \
75 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
76 SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
78 warning2(__VA_ARGS__); \
80 # define warningx(...) do { \
81 sudo_debug_printf2(__func__, __FILE__, __LINE__, \
82 SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|sudo_debug_subsys, __VA_ARGS__); \
83 warningx2(__VA_ARGS__); \
85 # endif /* __GNUC__ == 2 */
86 #endif /* SUDO_ERROR_WRAP */
88 void error2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
89 void errorx2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
90 void warning2(const char *, ...) __printflike(1, 2);
91 void warningx2(const char *, ...) __printflike(1, 2);
93 #endif /* _SUDO_ERROR_H_ */