Commit 52e53a76d for llama.cpp
commit 52e53a76df0298d2c316ae7e704eeec03b0bf478
Author: Adrien Gallouët <angt@huggingface.co>
Date: Wed Nov 4 14:21:38 2026 +0100
common : delete common_get_path_from_env() (#31444)
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
diff --git a/common/arg.cpp b/common/arg.cpp
index e3ab084c6..67b492e11 100644
--- a/common/arg.cpp
+++ b/common/arg.cpp
@@ -710,7 +710,7 @@ static void common_params_apply_system_config(common_params & params, llama_exam
std::vector<std::filesystem::path> paths;
#if defined(_WIN32)
- const std::filesystem::path program_data = common_get_path_from_env("PROGRAMDATA");
+ const std::filesystem::path program_data = common_get_env("PROGRAMDATA");
if (!program_data.empty()) {
paths.push_back(program_data / "llama.cpp" / "config.ini");
}
diff --git a/common/common.cpp b/common/common.cpp
index 95a2dceef..20285b6f7 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -983,20 +983,9 @@ void common_set_env(const std::string & name, const std::string & value) {
#endif
}
-std::filesystem::path common_get_path_from_env(const std::string & name) {
-#if defined(_WIN32)
- const std::wstring wname = utf8_to_wstring(name);
- const wchar_t * wvalue = _wgetenv(wname.c_str());
- return wvalue ? std::filesystem::path(wvalue) : std::filesystem::path();
-#else
- const char * value = std::getenv(name.c_str());
- return value ? std::filesystem::path(value) : std::filesystem::path();
-#endif
-}
-
#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;
}
@@ -1009,19 +998,19 @@ static std::filesystem::path get_home_directory() {
#endif
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";
}
@@ -1032,12 +1021,12 @@ std::filesystem::path fs_get_cache_directory() {
std::filesystem::path fs_get_config_directory() {
std::filesystem::path config_directory;
#if defined(_WIN32)
- config_directory = common_get_path_from_env("APPDATA");
+ config_directory = common_get_env("APPDATA");
if (config_directory.empty()) {
throw std::runtime_error("Failed to find %APPDATA% directory");
}
#else
- config_directory = common_get_path_from_env("XDG_CONFIG_HOME");
+ config_directory = common_get_env("XDG_CONFIG_HOME");
if (config_directory.empty()) {
config_directory = get_home_directory() / ".config";
}
diff --git a/common/common.h b/common/common.h
index e970fb39b..6ee90c1fe 100644
--- a/common/common.h
+++ b/common/common.h
@@ -919,9 +919,6 @@ std::string wstring_to_utf8(const std::wstring & str);
std::string common_get_env(const std::string & name);
void common_set_env(const std::string & name, const std::string & value);
-// reads a path from the environment, an unset variable gives an empty path
-std::filesystem::path common_get_path_from_env(const std::string & name);
-
//
// Filesystem utils
//
diff --git a/common/hf-cache.cpp b/common/hf-cache.cpp
index aafc940c5..a7f328fea 100644
--- a/common/hf-cache.cpp
+++ b/common/hf-cache.cpp
@@ -45,7 +45,7 @@ static fs::path get_cache_directory() {
{HOME_DIR, fs::path(".cache") / "huggingface" / "hub"}
};
for (const auto & entry : entries) {
- if (fs::path base = common_get_path_from_env(entry.var); !base.empty()) {
+ if (fs::path base = common_get_env(entry.var); !base.empty()) {
return entry.path.empty() ? base : base / entry.path;
}
}
diff --git a/tools/server/server-tools.cpp b/tools/server/server-tools.cpp
index ad6dd1d78..c1cf27cd2 100644
--- a/tools/server/server-tools.cpp
+++ b/tools/server/server-tools.cpp
@@ -128,13 +128,10 @@ static std::string path_to_utf8(const fs::path & p) {
static const std::string & home_dir() {
static const std::string home = [] {
#ifdef _WIN32
- // the narrow getenv would return the profile path in the active code page
- const wchar_t * w = _wgetenv(L"HOME");
- if (w == nullptr) w = _wgetenv(L"USERPROFILE");
- return w ? path_to_utf8(fs::path(w)) : std::string();
+ const std::string h = common_get_env("HOME");
+ return h.empty() ? common_get_env("USERPROFILE") : h;
#else
- const char * h = getenv("HOME");
- return h ? std::string(h) : std::string();
+ return common_get_env("HOME");
#endif
}();
return home;