Debian Codegraph @

lib/util/exit.h

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