assert.h 819 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #ifndef _ASSERT_H
  7. # define _ASSERT_H
  8. # define __stringify_helper(x) #x
  9. # define __stringify(x) __stringify_helper(x)
  10. # ifndef __cplusplus
  11. # define static_assert _Static_assert
  12. # endif
  13. #endif
  14. #include <sys/cdefs.h>
  15. #undef assert
  16. __BEGIN_DECLS
  17. #ifndef NDEBUG
  18. __attribute__((noreturn)) void __assertion_failed(char const* msg);
  19. # define assert(expr) \
  20. (__builtin_expect(!(expr), 0) \
  21. ? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \
  22. : (void)0)
  23. #else
  24. # define assert(expr) ((void)(0))
  25. #endif
  26. __END_DECLS