From 20b4585dbe953cb44a500caa183b9f23be1d8ed8 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Tue, 27 Aug 2019 23:33:42 +0200 Subject: [PATCH] process: Use environ from unistd.h if available --- CMakeLists.txt | 4 +++- src/configure.hpp.in | 1 + src/util/process.cpp | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b487d31..cdb9aca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,7 +263,9 @@ if(NOT WIN32) check_symbol_exists(utimes "sys/time.h" INNOEXTRACT_HAVE_UTIMES) endif() check_symbol_exists(posix_spawnp "spawn.h" INNOEXTRACT_HAVE_POSIX_SPAWNP) - if(NOT INNOEXTRACT_HAVE_POSIX_SPAWNP) + if(INNOEXTRACT_HAVE_POSIX_SPAWNP) + check_symbol_exists(environ "unistd.h" INNOEXTRACT_HAVE_UNISTD_ENVIRON) + else() check_symbol_exists(fork "unistd.h" INNOEXTRACT_HAVE_FORK) check_symbol_exists(execvp "unistd.h" INNOEXTRACT_HAVE_EXECVP) endif() diff --git a/src/configure.hpp.in b/src/configure.hpp.in index 223adb6..efdff49 100644 --- a/src/configure.hpp.in +++ b/src/configure.hpp.in @@ -41,6 +41,7 @@ // Process functions #cmakedefine01 INNOEXTRACT_HAVE_POSIX_SPAWNP +#cmakedefine01 INNOEXTRACT_HAVE_UNISTD_ENVIRON #cmakedefine01 INNOEXTRACT_HAVE_FORK #cmakedefine01 INNOEXTRACT_HAVE_EXECVP #cmakedefine01 INNOEXTRACT_HAVE_WAITPID diff --git a/src/util/process.cpp b/src/util/process.cpp index 60ac13a..749f28f 100644 --- a/src/util/process.cpp +++ b/src/util/process.cpp @@ -37,6 +37,7 @@ #if INNOEXTRACT_HAVE_POSIX_SPAWNP #include +#if !INNOEXTRACT_HAVE_UNISTD_ENVIRON extern "C" { #if defined(__FreeBSD__) && defined(__GNUC__) && __GNUC__ >= 4 /* @@ -48,7 +49,10 @@ extern char ** environ __attribute__((visibility("default"))); extern char ** environ; #endif } -#else +#endif +#endif + +#if INNOEXTRACT_HAVE_UNISTD_ENVIRON || (INNOEXTRACT_HAVE_FORK && INNOEXTRACT_HAVE_EXECVP) #include #endif