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.
This commit is contained in:
Rui Ueyama 2022-12-10 15:58:24 +08:00
parent c7d4a099d9
commit a96a5c89c1

View file

@ -479,20 +479,12 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) {
MI_UNUSED(result_size); MI_UNUSED(result_size);
return false; return false;
} }
#else #elif defined _WIN32
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
// On Windows use GetEnvironmentVariable instead of getenv to work // On Windows use GetEnvironmentVariable instead of getenv to work
// reliably even when this is invoked before the C runtime is initialized. // reliably even when this is invoked before the C runtime is initialized.
// i.e. when `_mi_preloading() == true`. // i.e. when `_mi_preloading() == true`.
// Note: on windows, environment names are not case sensitive. // Note: on windows, environment names are not case sensitive.
#include <windows.h> # include <windows.h>
static bool mi_getenv(const char* name, char* result, size_t result_size) { static bool mi_getenv(const char* name, char* result, size_t result_size) {
result[0] = 0; result[0] = 0;
size_t len = GetEnvironmentVariableA(name, result, (DWORD)result_size); 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) #elif !defined(MI_USE_ENVIRON) || (MI_USE_ENVIRON!=0)
// On Posix systemsr use `environ` to acces environment variables // On Posix systemsr use `environ` to acces environment variables
// even before the C runtime is initialized. // even before the C runtime is initialized.
#if defined(__APPLE__) && defined(__has_include) && __has_include(<crt_externs.h>) # if defined(__APPLE__) && defined(__has_include) && __has_include(<crt_externs.h>)
#include <crt_externs.h> # include <crt_externs.h>
static char** mi_get_environ(void) { static char** mi_get_environ(void) {
return (*_NSGetEnviron()); return (*_NSGetEnviron());
} }
#else # else
extern char** environ; extern char** environ;
static char** mi_get_environ(void) { static char** mi_get_environ(void) {
return environ; 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) { static bool mi_getenv(const char* name, char* result, size_t result_size) {
if (name==NULL) return false; if (name==NULL) return false;
const size_t len = strlen(name); 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; return false;
} }
} }
#endif // !MI_USE_ENVIRON
#endif // !MI_NO_GETENV #endif // !MI_NO_GETENV
static void mi_option_init(mi_option_desc_t* desc) { static void mi_option_init(mi_option_desc_t* desc) {