libose
Loading...
Searching...
No Matches
ose_assert.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019-23 John MacCallum Permission is hereby granted,
3 free of charge, to any person obtaining a copy of this software and
4 associated documentation files (the "Software"), to deal in the
5 Software without restriction, including without limitation the
6 rights to use, copy, modify, merge, publish, distribute, sublicense,
7 and/or sell copies of the Software, and to permit persons to whom
8 the Software is furnished to do so, subject to the following
9 conditions:
10
11 The above copyright notice and this permission notice shall be
12 included in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 SOFTWARE.
22*/
23
29#ifndef OSE_ASSERT_H
30#define OSE_ASSERT_H
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#include <assert.h>
37#include <stdio.h>
38#include <stdlib.h>
39
46#ifdef NDEBUG
47#define ose_assert(t) do {} while(0)
48#else
49#ifdef OSE_QUIET_ASSERT
50/* for running tests that expect failed assertions */
51#define ose_assert(t) \
52 !(t) \
53 ? abort() \
54 : (void)0
55#else
56#define ose_assert(t) \
57 !(t) \
58 ? ((void)fprintf(stderr, \
59 "Assertion failed: %s, " \
60 "function %s, " \
61 "file %s, " \
62 "line %d.\n", \
63 #t, __func__, __FILE__, __LINE__), \
64 abort()) \
65 : (void)0
66#endif
67#endif
68
69#ifdef OSE_DEBUG
70#define ose_always(t) ((t) ? 1 : (ose_assert(0), 0))
71#define ose_never(t) ((t) ? (assert(0), 0) : 1)
72#else
73#define ose_always(t) (t)
74#define ose_never(t) (t)
75#endif
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif