From 9c08cb9dd4824416598740dbded92bec152491a4 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 28 Oct 2020 16:21:01 +0100 Subject: [PATCH] Use __attribute__((destructor)), if supported by the compiler. --- Makefile | 4 ++-- libslunkcrypt/src/junk.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9332f7b..8f26ff6 100644 --- 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 diff --git a/libslunkcrypt/src/junk.c b/libslunkcrypt/src/junk.c index 98a4f1b..869028c 100644 --- a/libslunkcrypt/src/junk.c +++ b/libslunkcrypt/src/junk.c @@ -20,6 +20,15 @@ # include #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 */