diff --git a/src/options.c b/src/options.c index 367bc0d2..4de7fe97 100644 --- a/src/options.c +++ b/src/options.c @@ -479,20 +479,12 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) { MI_UNUSED(result_size); return false; } -#else -static inline int mi_strnicmp(const char* s, const char* t, size_t n) { - if (n==0) return 0; - for (; *s != 0 && *t != 0 && n > 0; s++, t++, n--) { - if (toupper(*s) != toupper(*t)) break; - } - return (n==0 ? 0 : *s - *t); -} -#if defined _WIN32 +#elif defined _WIN32 // On Windows use GetEnvironmentVariable instead of getenv to work // reliably even when this is invoked before the C runtime is initialized. // i.e. when `_mi_preloading() == true`. // Note: on windows, environment names are not case sensitive. -#include +# include static bool mi_getenv(const char* name, char* result, size_t result_size) { result[0] = 0; size_t len = GetEnvironmentVariableA(name, result, (DWORD)result_size); @@ -501,17 +493,25 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) { #elif !defined(MI_USE_ENVIRON) || (MI_USE_ENVIRON!=0) // On Posix systemsr use `environ` to acces environment variables // even before the C runtime is initialized. -#if defined(__APPLE__) && defined(__has_include) && __has_include() -#include +# if defined(__APPLE__) && defined(__has_include) && __has_include() +# include static char** mi_get_environ(void) { return (*_NSGetEnviron()); } -#else +# else extern char** environ; static char** mi_get_environ(void) { return environ; } -#endif +# endif +static inline int mi_strnicmp(const char* s, const char* t, size_t n) { + if (n==0) return 0; + for (; *s != 0 && *t != 0 && n > 0; s++, t++, n--) { + if (toupper(*s) != toupper(*t)) break; + } + return (n==0 ? 0 : *s - *t); +} + static bool mi_getenv(const char* name, char* result, size_t result_size) { if (name==NULL) return false; const size_t len = strlen(name); @@ -554,7 +554,6 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) { return false; } } -#endif // !MI_USE_ENVIRON #endif // !MI_NO_GETENV static void mi_option_init(mi_option_desc_t* desc) {