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(SUDO_DEBUG_ERROR|sudo_debug_subsys, (fmt)); \
42 error2((rval), (fmt)); \
44 # define errorx(rval, fmt...) do { \
45 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, (fmt)); \
46 errorx2((rval), (fmt)); \
48 # define warning(fmt...) do { \
49 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, (fmt)); \
52 # define warningx(fmt...) do { \
53 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, (fmt)); \
57 # define error(rval, ...) do { \
58 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, __VA_ARGS__); \
59 error2((rval), __VA_ARGS__); \
61 # define errorx(rval, ...) do { \
62 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, __VA_ARGS__); \
63 errorx2((rval), __VA_ARGS__); \
65 # define warning(...) do { \
66 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, __VA_ARGS__); \
67 warning2(__VA_ARGS__); \
69 # define warningx(...) do { \
70 sudo_debug_printf2(SUDO_DEBUG_ERROR|sudo_debug_subsys, __VA_ARGS__); \
71 warningx2(__VA_ARGS__); \
73 # endif /* __GNUC__ == 2 */
74 #endif /* SUDO_ERROR_WRAP */
76 void error2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
77 void errorx2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
78 void warning2(const char *, ...) __printflike(1, 2);
79 void warningx2(const char *, ...) __printflike(1, 2);
81 #endif /* _SUDO_ERROR_H_ */