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