17c478bd9Sstevel@tonic-gate /*
2*9525b14bSRao Shoaib  * Copyright (C) 2004, 2005, 2008  Internet Systems Consortium, Inc. ("ISC")
3*9525b14bSRao Shoaib  * Copyright (C) 1997-2001  Internet Software Consortium.
47c478bd9Sstevel@tonic-gate  *
5*9525b14bSRao Shoaib  * Permission to use, copy, modify, and/or distribute this software for any
67c478bd9Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
77c478bd9Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
87c478bd9Sstevel@tonic-gate  *
9*9525b14bSRao Shoaib  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10*9525b14bSRao Shoaib  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11*9525b14bSRao Shoaib  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12*9525b14bSRao Shoaib  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13*9525b14bSRao Shoaib  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14*9525b14bSRao Shoaib  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15*9525b14bSRao Shoaib  * PERFORMANCE OF THIS SOFTWARE.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate /*
19*9525b14bSRao Shoaib  * $Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp $
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #ifndef ASSERTIONS_H
237c478bd9Sstevel@tonic-gate #define ASSERTIONS_H		1
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate typedef enum {
267c478bd9Sstevel@tonic-gate 	assert_require, assert_ensure, assert_insist, assert_invariant
277c478bd9Sstevel@tonic-gate } assertion_type;
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate typedef void (*assertion_failure_callback)(const char *, int, assertion_type,
307c478bd9Sstevel@tonic-gate 					   const char *, int);
317c478bd9Sstevel@tonic-gate 
32*9525b14bSRao Shoaib /* coverity[+kill] */
337c478bd9Sstevel@tonic-gate extern assertion_failure_callback __assertion_failed;
347c478bd9Sstevel@tonic-gate void set_assertion_failure_callback(assertion_failure_callback f);
357c478bd9Sstevel@tonic-gate const char *assertion_type_to_text(assertion_type type);
367c478bd9Sstevel@tonic-gate 
37*9525b14bSRao Shoaib #if defined(CHECK_ALL) || defined(__COVERITY__)
387c478bd9Sstevel@tonic-gate #define CHECK_REQUIRE		1
397c478bd9Sstevel@tonic-gate #define CHECK_ENSURE		1
407c478bd9Sstevel@tonic-gate #define CHECK_INSIST		1
417c478bd9Sstevel@tonic-gate #define CHECK_INVARIANT		1
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
44*9525b14bSRao Shoaib #if defined(CHECK_NONE) && !defined(__COVERITY__)
457c478bd9Sstevel@tonic-gate #define CHECK_REQUIRE		0
467c478bd9Sstevel@tonic-gate #define CHECK_ENSURE		0
477c478bd9Sstevel@tonic-gate #define CHECK_INSIST		0
487c478bd9Sstevel@tonic-gate #define CHECK_INVARIANT		0
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #ifndef CHECK_REQUIRE
527c478bd9Sstevel@tonic-gate #define CHECK_REQUIRE		1
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifndef CHECK_ENSURE
567c478bd9Sstevel@tonic-gate #define CHECK_ENSURE		1
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #ifndef CHECK_INSIST
607c478bd9Sstevel@tonic-gate #define CHECK_INSIST		1
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #ifndef CHECK_INVARIANT
647c478bd9Sstevel@tonic-gate #define CHECK_INVARIANT		1
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #if CHECK_REQUIRE != 0
687c478bd9Sstevel@tonic-gate #define REQUIRE(cond) \
697c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
707c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
717c478bd9Sstevel@tonic-gate 				       #cond, 0), 0)))
727c478bd9Sstevel@tonic-gate #define REQUIRE_ERR(cond) \
737c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
747c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
757c478bd9Sstevel@tonic-gate 				       #cond, 1), 0)))
767c478bd9Sstevel@tonic-gate #else
777c478bd9Sstevel@tonic-gate #define REQUIRE(cond)		((void) (cond))
787c478bd9Sstevel@tonic-gate #define REQUIRE_ERR(cond)	((void) (cond))
797c478bd9Sstevel@tonic-gate #endif /* CHECK_REQUIRE */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #if CHECK_ENSURE != 0
827c478bd9Sstevel@tonic-gate #define ENSURE(cond) \
837c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
847c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
857c478bd9Sstevel@tonic-gate 				       #cond, 0), 0)))
867c478bd9Sstevel@tonic-gate #define ENSURE_ERR(cond) \
877c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
887c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
897c478bd9Sstevel@tonic-gate 				       #cond, 1), 0)))
907c478bd9Sstevel@tonic-gate #else
917c478bd9Sstevel@tonic-gate #define ENSURE(cond)		((void) (cond))
927c478bd9Sstevel@tonic-gate #define ENSURE_ERR(cond)	((void) (cond))
937c478bd9Sstevel@tonic-gate #endif /* CHECK_ENSURE */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #if CHECK_INSIST != 0
967c478bd9Sstevel@tonic-gate #define INSIST(cond) \
977c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
987c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
997c478bd9Sstevel@tonic-gate 				       #cond, 0), 0)))
1007c478bd9Sstevel@tonic-gate #define INSIST_ERR(cond) \
1017c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
1027c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
1037c478bd9Sstevel@tonic-gate 				       #cond, 1), 0)))
1047c478bd9Sstevel@tonic-gate #else
1057c478bd9Sstevel@tonic-gate #define INSIST(cond)		((void) (cond))
1067c478bd9Sstevel@tonic-gate #define INSIST_ERR(cond)	((void) (cond))
1077c478bd9Sstevel@tonic-gate #endif /* CHECK_INSIST */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #if CHECK_INVARIANT != 0
1107c478bd9Sstevel@tonic-gate #define INVARIANT(cond) \
1117c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
1127c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
1137c478bd9Sstevel@tonic-gate 				       #cond, 0), 0)))
1147c478bd9Sstevel@tonic-gate #define INVARIANT_ERR(cond) \
1157c478bd9Sstevel@tonic-gate 	((void) ((cond) || \
1167c478bd9Sstevel@tonic-gate 		 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
1177c478bd9Sstevel@tonic-gate 				       #cond, 1), 0)))
1187c478bd9Sstevel@tonic-gate #else
1197c478bd9Sstevel@tonic-gate #define INVARIANT(cond)		((void) (cond))
1207c478bd9Sstevel@tonic-gate #define INVARIANT_ERR(cond)	((void) (cond))
1217c478bd9Sstevel@tonic-gate #endif /* CHECK_INVARIANT */
1227c478bd9Sstevel@tonic-gate #endif /* ASSERTIONS_H */
123*9525b14bSRao Shoaib /*! \file */
124