From a96a5c89c17767f5e6a6f281d8d174a934307a53 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 10 Dec 2022 15:58:24 +0800 Subject: [PATCH] Fix -Wunused-function `mi_strnicmp` is defined but not used If `MI_USE_ENVIRON` is not set, which triggers a `-Wunused-function` warning. Since the function is used only by `mi_getenv`, we can move the `mi_strnicmp` just before `mi_getenv` to fix the warning. --- src/options.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) 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) {