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