From 7e42b95f231e508a001b6006fa73abbbbc1da3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 5 Nov 2026 08:36:51 +0100 Subject: [PATCH] rpc : align code with common.cpp (#31684) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- tools/rpc/rpc-server.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/tools/rpc/rpc-server.cpp b/tools/rpc/rpc-server.cpp index 7cb25947d..8aeb15db5 100644 --- a/tools/rpc/rpc-server.cpp +++ b/tools/rpc/rpc-server.cpp @@ -10,7 +10,6 @@ #endif #include #include -#include #include #include #include @@ -24,25 +23,16 @@ #endif -// common_get_path_from_env() is adapted to avoid utf8_to_wstring -static std::filesystem::path common_get_path_from_env(const std::string & name) { -#ifdef _WIN32 - std::wstring wname; - for (const char * p = name.c_str(); *p; ++p) { - wname.push_back((wchar_t)*p); - } - const wchar_t * wvalue = _wgetenv(wname.c_str()); - return wvalue ? std::filesystem::path(wvalue) : std::filesystem::path(); -#else +// NOTE: this is copied from common.cpp to avoid linking with libcommon +static std::string common_get_env(const std::string & name) { const char * value = std::getenv(name.c_str()); - return value ? std::filesystem::path(value) : std::filesystem::path(); -#endif + return value == nullptr ? "" : value; } // NOTE: this is copied from common.cpp to avoid linking with libcommon #if !defined(_WIN32) static std::filesystem::path get_home_directory() { - std::filesystem::path home = common_get_path_from_env("HOME"); + std::filesystem::path home = common_get_env("HOME"); if (!home.empty()) { return home; } @@ -56,19 +46,19 @@ static std::filesystem::path get_home_directory() { // NOTE: this is copied from common.cpp to avoid linking with libcommon static std::filesystem::path fs_get_cache_directory() { - std::filesystem::path cache_directory = common_get_path_from_env("LLAMA_CACHE"); + std::filesystem::path cache_directory = common_get_env("LLAMA_CACHE"); if (!cache_directory.empty()) { return cache_directory; } #if defined(_WIN32) - cache_directory = common_get_path_from_env("LOCALAPPDATA"); + cache_directory = common_get_env("LOCALAPPDATA"); if (cache_directory.empty()) { throw std::runtime_error("Failed to find %LOCALAPPDATA% directory"); } #elif defined(__APPLE__) cache_directory = get_home_directory() / "Library/Caches"; #else - cache_directory = common_get_path_from_env("XDG_CACHE_HOME"); + cache_directory = common_get_env("XDG_CACHE_HOME"); if (cache_directory.empty()) { cache_directory = get_home_directory() / ".cache"; }