From ad725d34cc438c9eee83dd7411bedd9ff9e3bdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E7=BA=BF=E6=9D=86?= <446100240@qq.com> Date: Mon, 9 Jun 2025 04:16:34 +0800 Subject: [PATCH] Use std::getenv #3414 (#3415) --- include/spdlog/cfg/helpers-inl.h | 2 +- include/spdlog/details/os-inl.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/spdlog/cfg/helpers-inl.h b/include/spdlog/cfg/helpers-inl.h index 1b2a5049..61b9b9f6 100644 --- a/include/spdlog/cfg/helpers-inl.h +++ b/include/spdlog/cfg/helpers-inl.h @@ -71,7 +71,7 @@ inline std::unordered_map extract_key_vals_(const std: } SPDLOG_INLINE void load_levels(const std::string &input) { - if (input.empty() || input.size() > 512) { + if (input.empty() || input.size() >= 32768) { return; } diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 3aaa6b54..807ea0af 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -563,21 +563,21 @@ SPDLOG_INLINE filename_t dir_name(const filename_t &path) { return pos != filename_t::npos ? path.substr(0, pos) : filename_t{}; } +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable : 4996) +#endif // _MSC_VER std::string SPDLOG_INLINE getenv(const char *field) { -#if defined(_MSC_VER) - #if defined(__cplusplus_winrt) +#if defined(_MSC_VER) && defined(__cplusplus_winrt) return std::string{}; // not supported under uwp - #else - size_t len = 0; - char buf[128]; - bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0; - return ok ? buf : std::string{}; - #endif -#else // revert to getenv - char *buf = ::getenv(field); +#else + char *buf = std::getenv(field); return buf ? buf : std::string{}; #endif } +#ifdef _MSC_VER + #pragma warning(pop) +#endif // _MSC_VER // Do fsync by FILE handlerpointer // Return true on success