mhd_assert.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. This file is part of libmicrohttpd
  3. Copyright (C) 2017 Karlson2k (Evgeny Grin)
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library.
  14. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /**
  17. * @file microhttpd/mhd_assert.h
  18. * @brief macros for mhd_assert()
  19. * @author Karlson2k (Evgeny Grin)
  20. */
  21. #ifndef MHD_ASSERT_H
  22. #define MHD_ASSERT_H 1
  23. #include "mhd_options.h"
  24. #ifdef NDEBUG
  25. # define mhd_assert(ignore) ((void) 0)
  26. #else /* _DEBUG */
  27. # ifdef HAVE_ASSERT
  28. # include <assert.h>
  29. # define mhd_assert(CHK) assert (CHK)
  30. # else /* ! HAVE_ASSERT */
  31. # include <stdio.h>
  32. # include <stdlib.h>
  33. # define mhd_assert(CHK) \
  34. do { \
  35. if (! (CHK)) { \
  36. fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \
  37. __FILE__, (unsigned) __LINE__, #CHK); \
  38. fflush (stderr); abort (); } \
  39. } while (0)
  40. # endif /* ! HAVE_ASSERT */
  41. #endif /* _DEBUG */
  42. #endif /* ! MHD_ASSERT_H */