xref: /titanic_50/usr/src/lib/libresolv2/include/isc/assertions.h (revision 80148899834a4078a2bd348504aa2d6de9752837)
1 /*
2  * Copyright (C) 2004, 2005, 2008  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1997-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /*
19  * $Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp $
20  */
21 
22 #ifndef ASSERTIONS_H
23 #define ASSERTIONS_H		1
24 
25 typedef enum {
26 	assert_require, assert_ensure, assert_insist, assert_invariant
27 } assertion_type;
28 
29 typedef void (*assertion_failure_callback)(const char *, int, assertion_type,
30 					   const char *, int);
31 
32 /* coverity[+kill] */
33 extern assertion_failure_callback __assertion_failed;
34 void set_assertion_failure_callback(assertion_failure_callback f);
35 const char *assertion_type_to_text(assertion_type type);
36 
37 #if defined(CHECK_ALL) || defined(__COVERITY__)
38 #define CHECK_REQUIRE		1
39 #define CHECK_ENSURE		1
40 #define CHECK_INSIST		1
41 #define CHECK_INVARIANT		1
42 #endif
43 
44 #if defined(CHECK_NONE) && !defined(__COVERITY__)
45 #define CHECK_REQUIRE		0
46 #define CHECK_ENSURE		0
47 #define CHECK_INSIST		0
48 #define CHECK_INVARIANT		0
49 #endif
50 
51 #ifndef CHECK_REQUIRE
52 #define CHECK_REQUIRE		1
53 #endif
54 
55 #ifndef CHECK_ENSURE
56 #define CHECK_ENSURE		1
57 #endif
58 
59 #ifndef CHECK_INSIST
60 #define CHECK_INSIST		1
61 #endif
62 
63 #ifndef CHECK_INVARIANT
64 #define CHECK_INVARIANT		1
65 #endif
66 
67 #if CHECK_REQUIRE != 0
68 #define REQUIRE(cond) \
69 	((void) ((cond) || \
70 		 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
71 				       #cond, 0), 0)))
72 #define REQUIRE_ERR(cond) \
73 	((void) ((cond) || \
74 		 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
75 				       #cond, 1), 0)))
76 #else
77 #define REQUIRE(cond)		((void) (cond))
78 #define REQUIRE_ERR(cond)	((void) (cond))
79 #endif /* CHECK_REQUIRE */
80 
81 #if CHECK_ENSURE != 0
82 #define ENSURE(cond) \
83 	((void) ((cond) || \
84 		 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
85 				       #cond, 0), 0)))
86 #define ENSURE_ERR(cond) \
87 	((void) ((cond) || \
88 		 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
89 				       #cond, 1), 0)))
90 #else
91 #define ENSURE(cond)		((void) (cond))
92 #define ENSURE_ERR(cond)	((void) (cond))
93 #endif /* CHECK_ENSURE */
94 
95 #if CHECK_INSIST != 0
96 #define INSIST(cond) \
97 	((void) ((cond) || \
98 		 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
99 				       #cond, 0), 0)))
100 #define INSIST_ERR(cond) \
101 	((void) ((cond) || \
102 		 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
103 				       #cond, 1), 0)))
104 #else
105 #define INSIST(cond)		((void) (cond))
106 #define INSIST_ERR(cond)	((void) (cond))
107 #endif /* CHECK_INSIST */
108 
109 #if CHECK_INVARIANT != 0
110 #define INVARIANT(cond) \
111 	((void) ((cond) || \
112 		 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
113 				       #cond, 0), 0)))
114 #define INVARIANT_ERR(cond) \
115 	((void) ((cond) || \
116 		 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
117 				       #cond, 1), 0)))
118 #else
119 #define INVARIANT(cond)		((void) (cond))
120 #define INVARIANT_ERR(cond)	((void) (cond))
121 #endif /* CHECK_INVARIANT */
122 #endif /* ASSERTIONS_H */
123 /*! \file */
124