2010-11-04 00:46:47 +03:00
|
|
|
/*
|
2015-04-16 14:03:40 +03:00
|
|
|
* Copyright 2004-2015 Haiku, Inc. All Rights Reserved.
|
2010-11-04 00:46:47 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
2015-04-16 22:03:40 +03:00
|
|
|
/* Include guards are omitted, as assert.h is required
|
|
|
|
to support being included multiple times.
|
|
|
|
|
|
|
|
E.g. the following is required to be valid:
|
|
|
|
|
|
|
|
#undef NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
assert(0); // this assertion will be triggered
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
assert(0); // this assertion will not be triggered
|
|
|
|
*/
|
|
|
|
|
2004-06-30 06:34:10 +04:00
|
|
|
#undef assert
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2008-05-11 01:30:34 +04:00
|
|
|
/* defining NDEBUG disables assert() functionality */
|
2004-06-30 06:34:10 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern void __assert_fail(const char *assertion, const char *file,
|
2011-05-21 17:15:46 +04:00
|
|
|
unsigned int line, const char *function)
|
|
|
|
__attribute__ ((noreturn));
|
2004-06-30 06:34:10 +04:00
|
|
|
|
|
|
|
extern void __assert_perror_fail(int error, const char *file,
|
2011-05-21 17:15:46 +04:00
|
|
|
unsigned int line, const char *function)
|
|
|
|
__attribute__ ((noreturn));
|
2004-06-30 06:34:10 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define assert(assertion) \
|
|
|
|
((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
|
|
|
|
2008-05-11 01:30:34 +04:00
|
|
|
#else /* NDEBUG */
|
|
|
|
# define assert(condition) ((void)0)
|
2004-06-30 06:34:10 +04:00
|
|
|
#endif
|