GNU libmicrohttpd  0.9.75
mhd_assert.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2017-2021 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 #define NDEBUG 1 /* Use NDEBUG by default */
36 #endif /* !_DEBUG && !NDEBUG */
37 #if defined(_DEBUG) && defined(NDEBUG)
38 #error Both _DEBUG and NDEBUG are defined
39 #endif /* _DEBUG && NDEBUG */
40 #ifdef NDEBUG
41 # define mhd_assert(ignore) ((void) 0)
42 #else /* _DEBUG */
43 # ifdef HAVE_ASSERT
44 # include <assert.h>
45 # define mhd_assert(CHK) assert (CHK)
46 # else /* ! HAVE_ASSERT */
47 # include <stdio.h>
48 # include <stdlib.h>
49 # define mhd_assert(CHK) \
50  do { \
51  if (! (CHK)) { \
52  fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \
53  __FILE__, (unsigned) __LINE__, #CHK); \
54  fflush (stderr); abort (); } \
55  } while (0)
56 # endif /* ! HAVE_ASSERT */
57 #endif /* _DEBUG */
58 
59 #endif /* ! MHD_ASSERT_H */
additional automatic macros for MHD_config.h