sg_assert.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* _
  2. * ___ __ _ __ _ _ _(_)
  3. * / __|/ _` |/ _` | | | | |
  4. * \__ \ (_| | (_| | |_| | |
  5. * |___/\__,_|\__, |\__,_|_|
  6. * |___/
  7. *
  8. * Cross-platform library which helps to develop web servers or frameworks.
  9. *
  10. * Copyright (C) 2016-2020 Silvio Clecio <[email protected]>
  11. *
  12. * Sagui library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Lesser General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2.1 of the License, or (at your option) any later version.
  16. *
  17. * Sagui library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Lesser General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Lesser General Public
  23. * License along with Sagui library; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. */
  26. #ifndef SG_ASSERT_H
  27. #define SG_ASSERT_H
  28. #ifndef _WIN32
  29. #ifndef _GNU_SOURCE
  30. #define _GNU_SOURCE
  31. #endif /* _GNU_SOURCE */
  32. #endif /* _WIN32 */
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <errno.h>
  36. #include <unistd.h>
  37. #ifdef _WIN32
  38. #define __progname __argv[0]
  39. #else /* _WIN32 */
  40. #if defined(__USE_GNU) && !defined(__i386__) && !defined(__ANDROID__)
  41. #define __progname program_invocation_short_name
  42. #else /* __USE_GNU && !__i386__ && !__ANDROID__ */
  43. extern const char *__progname;
  44. #endif /* __USE_GNU && !__i386__ && !__ANDROID__ */
  45. #endif /* _WIN32 */
  46. #ifdef NDEBUG
  47. #define ASSERT(expr) ((void) 0)
  48. #else /* NDEBUG */
  49. #define ASSERT(expr) \
  50. do { \
  51. if (!(expr)) { \
  52. if ((fprintf(stderr, "%s: %s:%d: %s: Assertion `%s' failed.\n", \
  53. __progname, __FILE__, __LINE__, __extension__ __FUNCTION__, \
  54. #expr) > 0)) \
  55. fflush(stderr); \
  56. exit(EXIT_FAILURE); \
  57. } \
  58. } while (0)
  59. #endif /* NDEBUG */
  60. #endif /* SG_ASSERT_H */