1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/libc/include/assert.h
Jonas 'Sortie' Termansen d43a044575 Refactor assert(3).
2013-12-17 14:30:45 +01:00

63 lines
1.9 KiB
C

/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
assert.h
Verify program assertion.
*******************************************************************************/
#ifndef INCLUDE_ASSERT_H
#define INCLUDE_ASSERT_H
#include <sys/cdefs.h>
__BEGIN_DECLS
/* Determine how the value should be cast to void. */
#if defined __cplusplus
#define __ASSERT_VOID_CAST(x) static_cast<void>(x)
#else
#define __ASSERT_VOID_CAST(x) (void) x
#endif
/* The actual implementation of assert. */
__attribute__((noreturn))
void __assert(const char*, unsigned long, const char*, const char*);
__END_DECLS
#endif
/* Rid ourselves of any previous declaration of assert. */
#ifdef assert
#undef assert
#endif
/* If not debugging, we'll declare a no-operation assert macro. */
#if defined(NDEBUG)
#define assert(ignore) (__ASSERT_VOID_CAST(0))
#endif
/* Otherwise, declare the normal assert macro. */
#if !defined(NDEBUG)
#define assert(invariant) \
((invariant) \
? __ASSERT_VOID_CAST(0) \
: __assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant))
#endif