OSDN Git Service

Use __attribute__((destructor)), if supported by the compiler.
authorLoRd_MuldeR <mulder2@gmx.de>
Wed, 28 Oct 2020 15:21:01 +0000 (16:21 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 20 Mar 2021 20:18:45 +0000 (21:18 +0100)
Makefile
libslunkcrypt/src/junk.c

index 9332f7b..8f26ff6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,13 +33,13 @@ endif
 
 MACHINE := $(shell $(CC) -dumpmachine)
 
-ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
+ifneq ($(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
   SUFFIX := .exe
 else
   SUFFIX :=
 endif
 
-ifeq ($(filter %-mingw32 %-windows-gnu,$(MACHINE)),)
+ifeq ($(filter %mingw32 %-windows-gnu,$(MACHINE)),)
   LDFLGS += -lpthread
 endif
 
index 98a4f1b..869028c 100644 (file)
 #      include <pthread.h>
 #endif
 
+/* Compiler compatibility */
+#if defined(__GNUC__) || defined(__clang__)
+#      define AT_EXIT(X) ((void)0)
+#      define DESTRUCTOR __attribute__((destructor))
+#else
+#      define AT_EXIT(X) atexit((X))
+#      define DESTRUCTOR
+#endif
+
 // ==========================================================================
 // One-time init
 // ==========================================================================
@@ -82,7 +91,7 @@ static int s_random_fd = -1;
 #endif
 
 /* Close down CSRNG */
-static void exit_random_source(void)
+static DESTRUCTOR void exit_random_source(void)
 {
 #if defined(_WIN32)
        s_rtl_genrandom = NULL;
@@ -117,7 +126,7 @@ static void init_random_source(void)
                }
        }
 #endif
-       atexit(exit_random_source);
+       AT_EXIT(exit_random_source);
 }
 
 /* Generate random bytes */