GNU libmicrohttpd  1.0.1
mhd_assert.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2017-2022 Karlson2k (Evgeny Grin)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library.
17  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
26 /* Unlike POSIX version of 'assert.h', MHD version of 'assert' header
27  * does not allow multiple redefinition of 'mhd_assert' macro within single
28  * source file. */
29 #ifndef MHD_ASSERT_H
30 #define MHD_ASSERT_H 1
31 
32 #include "mhd_options.h"
33 
34 #if ! defined(_DEBUG) && ! defined(NDEBUG)
35 #ifndef DEBUG /* Used by some toolchains */
36 #define NDEBUG 1 /* Use NDEBUG by default */
37 #else /* DEBUG */
38 #define _DEBUG 1
39 #endif /* DEBUG */
40 #endif /* !_DEBUG && !NDEBUG */
41 #if defined(_DEBUG) && defined(NDEBUG)
42 #error Both _DEBUG and NDEBUG are defined
43 #endif /* _DEBUG && NDEBUG */
44 #ifdef NDEBUG
45 # define mhd_assert(ignore) ((void) 0)
46 #else /* _DEBUG */
47 # ifdef HAVE_ASSERT
48 # include <assert.h>
49 # define mhd_assert(CHK) assert (CHK)
50 # else /* ! HAVE_ASSERT */
51 # include <stdio.h>
52 # include <stdlib.h>
53 # define mhd_assert(CHK) \
54  do { \
55  if (! (CHK)) { \
56  fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \
57  __FILE__, (unsigned) __LINE__, #CHK); \
58  fflush (stderr); abort (); } \
59  } while (0)
60 # endif /* ! HAVE_ASSERT */
61 #endif /* _DEBUG */
62 
63 #endif /* ! MHD_ASSERT_H */
additional automatic macros for MHD_config.h