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