exit.h 700 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /// @file
  2. /// @ingroup cgraph_utils
  3. #pragma once
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #ifdef __cplusplus
  7. #include <iostream>
  8. extern "C" {
  9. #endif
  10. #ifdef __GNUC__
  11. // FIXME: use `[[noreturn]]` for all compilers when we move to C23
  12. #define NORETURN __attribute__((noreturn))
  13. #elif defined(_MSC_VER)
  14. #define NORETURN __declspec(noreturn)
  15. #else
  16. #define NORETURN /* nothing */
  17. #endif
  18. static inline NORETURN void graphviz_exit(int status) {
  19. #ifdef _WIN32
  20. // workaround for https://gitlab.com/graphviz/graphviz/-/issues/2178
  21. fflush(stdout);
  22. fflush(stderr);
  23. #ifdef __cplusplus
  24. std::cout.flush();
  25. std::cerr.flush();
  26. #endif
  27. #endif
  28. exit(status);
  29. }
  30. #undef NORETURN
  31. #ifdef __cplusplus
  32. }
  33. #endif