xref: /haiku/headers/posix/assert.h (revision bb83316a5811a550c4f850d07fa8e328e7ac0a94)
1  /*
2   * Copyright 2004-2015 Haiku, Inc. All Rights Reserved.
3   * Distributed under the terms of the MIT License.
4   */
5  
6  /* Include guards are only on part of the file, as assert.h is required
7     to support being included multiple times.
8  
9     E.g. the following is required to be valid:
10  
11     #undef NDEBUG
12     #include <assert.h>
13  
14     assert(0); // this assertion will be triggered
15  
16     #define NDEBUG
17     #include <assert.h>
18  
19     assert(0); // this assertion will not be triggered
20  */
21  
22  #undef assert
23  
24  #ifndef NDEBUG
25  	/* defining NDEBUG disables assert() functionality */
26  
27  #ifndef _ASSERT_H_
28  #define _ASSERT_H_
29  
30  #ifdef __cplusplus
31  extern "C" {
32  #endif
33  
34  extern void __assert_fail(const char *assertion, const char *file,
35  				unsigned int line, const char *function)
36  	__attribute__ ((noreturn));
37  
38  extern void __assert_perror_fail(int error, const char *file,
39  				unsigned int line, const char *function)
40  	__attribute__ ((noreturn));
41  
42  #ifdef __cplusplus
43  }
44  #endif
45  
46  #endif /* !_ASSERT_H_ */
47  
48  #define assert(assertion) \
49  	((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
50  
51  #else	/* NDEBUG */
52  #	define assert(condition) ((void)0)
53  #endif
54  
55  #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(static_assert)
56  #	define static_assert _Static_assert
57  #endif
58