home_directory()
{
#ifdef _WIN32
- if (const char* p = getenv("USERPROFILE")) {
- return p;
+ auto user_profile = util::getenv_path("USERPROFILE");
+ if (user_profile) {
+ return *user_profile;
}
throw core::Fatal(
"The USERPROFILE environment variable must be set to your user profile"
" folder");
#else
- if (const char* p = getenv("HOME")) {
- return p;
+ auto home = util::getenv_path("HOME");
+ if (home) {
+ return *home;
}
# ifdef HAVE_GETPWUID
{
const bool legacy_ccache_dir_exists =
DirEntry(legacy_ccache_dir).is_directory();
#ifdef _WIN32
- const char* const env_appdata = getenv("APPDATA");
- const char* const env_local_appdata = getenv("LOCALAPPDATA");
+ auto env_appdata = util::getenv_path("APPDATA");
+ auto env_local_appdata = util::getenv_path("LOCALAPPDATA");
#else
- const char* const env_xdg_cache_home = getenv("XDG_CACHE_HOME");
- const char* const env_xdg_config_home = getenv("XDG_CONFIG_HOME");
+ auto env_xdg_cache_home = util::getenv_path("XDG_CACHE_HOME");
+ auto env_xdg_config_home = util::getenv_path("XDG_CONFIG_HOME");
#endif
- const char* env_ccache_configpath = getenv("CCACHE_CONFIGPATH");
+ auto env_ccache_configpath = util::getenv_path("CCACHE_CONFIGPATH");
if (env_ccache_configpath) {
- set_config_path(env_ccache_configpath);
+ set_config_path(*env_ccache_configpath);
} else {
// Only used for ccache tests:
- const char* const env_ccache_configpath2 = getenv("CCACHE_CONFIGPATH2");
+ auto env_ccache_configpath2 = util::getenv_path("CCACHE_CONFIGPATH2");
fs::path sysconfdir(k_sysconfdir);
#ifdef _WIN32
- if (const char* program_data = getenv("ALLUSERSPROFILE"))
- sysconfdir = fs::path(program_data) / "ccache";
+ auto program_data = util::getenv_path("ALLUSERSPROFILE");
+ if (program_data) {
+ sysconfdir = *program_data / "ccache";
+ }
#endif
- set_system_config_path(env_ccache_configpath2 ? env_ccache_configpath2
+ set_system_config_path(env_ccache_configpath2 ? *env_ccache_configpath2
: sysconfdir / "ccache.conf");
// A missing config file in SYSCONFDIR is OK so don't check return value.
update_from_file(system_config_path());
- const char* const env_ccache_dir = getenv("CCACHE_DIR");
+ auto env_ccache_dir = util::getenv_path("CCACHE_DIR");
auto cmdline_cache_dir = cmdline_settings_map.find("cache_dir");
fs::path config_dir;
if (cmdline_cache_dir != cmdline_settings_map.end()) {
config_dir = cmdline_cache_dir->second;
- } else if (env_ccache_dir && *env_ccache_dir) {
- config_dir = env_ccache_dir;
+ } else if (env_ccache_dir && !env_ccache_dir->empty()) {
+ config_dir = *env_ccache_dir;
} else if (!cache_dir().empty() && !env_ccache_dir) {
config_dir = cache_dir();
} else if (legacy_ccache_dir_exists) {
config_dir = legacy_ccache_dir;
#ifdef _WIN32
} else if (env_local_appdata
- && DirEntry(
- make_path(env_local_appdata, "ccache", "ccache.conf"))) {
- config_dir = make_path(env_local_appdata, "ccache");
- } else if (env_appdata
- && DirEntry(make_path(env_appdata, "ccache", "ccache.conf"))) {
- config_dir = make_path(env_appdata, "ccache");
+ && fs::exists(*env_local_appdata / "ccache/ccache.conf")) {
+ config_dir = *env_local_appdata / "ccache";
+ } else if (env_appdata && fs::exists(*env_appdata / "ccache/ccache.conf")) {
+ config_dir = make_path(*env_appdata, "ccache");
} else if (env_local_appdata) {
- config_dir = make_path(env_local_appdata, "ccache");
+ config_dir = *env_local_appdata / "ccache";
} else {
throw core::Fatal(
"could not find configuration file and the LOCALAPPDATA environment"
}
#else
} else if (env_xdg_config_home) {
- config_dir = make_path(env_xdg_config_home, "ccache");
+ config_dir = *env_xdg_config_home / "ccache";
} else {
config_dir = default_config_dir(home_dir);
}
set_cache_dir(legacy_ccache_dir);
#ifdef _WIN32
} else if (env_local_appdata) {
- set_cache_dir(fs::path(env_local_appdata) / "ccache");
+ set_cache_dir(*env_local_appdata / "ccache");
} else {
throw core::Fatal(
"could not find cache directory and the LOCALAPPDATA environment"
}
#else
} else if (env_xdg_cache_home) {
- set_cache_dir(make_path(env_xdg_cache_home, "ccache"));
+ set_cache_dir(*env_xdg_cache_home / "ccache");
} else {
set_cache_dir(default_cache_dir(home_dir));
}