]> granicus.if.org Git - graphviz/commitdiff
cgraph: add a graphviz_exit function in a new header file exit.h
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sun, 16 Jan 2022 15:40:29 +0000 (16:40 +0100)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 31 Jan 2022 07:26:19 +0000 (08:26 +0100)
Towards https://gitlab.com/graphviz/graphviz/-/issues/2178.

lib/cgraph/CMakeLists.txt
lib/cgraph/Makefile.am
lib/cgraph/cgraph.vcxproj
lib/cgraph/cgraph.vcxproj.filters
lib/cgraph/exit.h [new file with mode: 0644]

index 81edb03d78ed47bfe6e6d8cf92b0ca7faaef6a42..ab411429a904d7f7b6b2e15fc75f3981fd04385f 100644 (file)
@@ -13,6 +13,7 @@ add_library(cgraph SHARED
     bitarray.h
     cghdr.h
     cgraph.h
+    exit.h
     itos.h
     likely.h
     prisize_t.h
index 795c975cee80c4680fca9d1b28be596de6b3c65a..d7272fda8ed8f810c8b191ae451545c29773d837 100644 (file)
@@ -12,7 +12,7 @@ AM_CFLAGS = -DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR
 endif
 
 pkginclude_HEADERS = cgraph.h
-noinst_HEADERS = agxbuf.h bitarray.h cghdr.h itos.h likely.h prisize_t.h \
+noinst_HEADERS = agxbuf.h bitarray.h cghdr.h exit.h itos.h likely.h prisize_t.h \
        sprint.h strcasecmp.h unreachable.h
 noinst_LTLIBRARIES = libcgraph_C.la
 lib_LTLIBRARIES = libcgraph.la
index 052a3bba77d554021c945075fa10031ab97ca4ef..99b9de6214d327063247ad1fa6bc9734dbe2dbfa 100644 (file)
@@ -101,6 +101,7 @@ win_flex -oscan.c scan.l</Command>
     <ClInclude Include="bitarray.h" />
     <ClInclude Include="cghdr.h" />
     <ClInclude Include="cgraph.h" />
+    <ClInclude Include="exit.h" />
     <ClInclude Include="itos.h" />
     <ClInclude Include="likely.h" />
     <ClInclude Include="prisize_t.h" />
index a20bf8fa77c09c6d50884240926b0e491c0dcd37..8c83513d3f66c166ec86e27dc289686b566006f7 100644 (file)
@@ -27,6 +27,9 @@
     <ClInclude Include="cgraph.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="exit.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="itos.h">
       <Filter>Header Files</Filter>
     </ClInclude>
diff --git a/lib/cgraph/exit.h b/lib/cgraph/exit.h
new file mode 100644 (file)
index 0000000..650951b
--- /dev/null
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __GNUC__
+// FIXME: use _Noreturn for all compilers when we move to C11
+#define NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define NORETURN __declspec(noreturn)
+#else
+#define NORETURN /* nothing */
+#endif
+
+static inline NORETURN void graphviz_exit(int status) {
+#ifdef __MINGW32__
+  // workaround for https://gitlab.com/graphviz/graphviz/-/issues/2178
+  fflush(stdout);
+  fflush(stderr);
+#endif
+  exit(status);
+}
+
+#undef NORETURN
+
+#ifdef __cplusplus
+}
+#endif