From a222773214a784e82b3f97dcc318c4c4b1c55ab4 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Fri, 1 Dec 2023 16:01:45 -0800 Subject: [PATCH] Add compatibility layer for env setting. --- main.cpp | 3 ++- win32compat.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 win32compat.h diff --git a/main.cpp b/main.cpp index d29fe95..31ae4dc 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "win32compat.h" #include "bitmapx16.h" using std::vector; using std::map; @@ -65,7 +66,7 @@ int main(int argc, char **argv) { bool probe_only = false; std::filesystem::path executable_path = std::filesystem::weakly_canonical(*argv).parent_path(); #ifdef _WIN32 - _setenv("MAGICK_CODER_MODULE_PATH", executable_path.c_str(), 0); + setenv("MAGICK_CODER_MODULE_PATH", executable_path.c_str(), 0); #endif InitializeMagick(*argv); argc--; diff --git a/win32compat.h b/win32compat.h new file mode 100644 index 0000000..8bb6212 --- /dev/null +++ b/win32compat.h @@ -0,0 +1,16 @@ +#pragma once + +#ifdef _WIN32 +#include +inline void setenv(char const *variable, char const *value, bool replace) { + if (replace || getenv(variable) == NULL || getenv(variable) == "") { + if (value == NULL) { + _putenv_s(variable, ""); + } else { + _putenv_s(variable, value); + } + } +} +#else +#include +#endif \ No newline at end of file