mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use the C++ std::getenv over the POSIX/C getenv
The C++ std::getenv is guaranteed thread-safe by the C++11 specification, whereas the POSIX/C getenv might not be thread-safe by the C11 specification.pull/9430/head
parent
d158eba72c
commit
3e4d327451
|
@ -822,7 +822,7 @@ static std::string GetHomeDir()
|
||||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||||
return std::string(path.Path());
|
return std::string(path.Path());
|
||||||
#else
|
#else
|
||||||
const char *home_env = getenv("HOME"); // Stack var, shouldn't be freed
|
const char *home_env = std::getenv("HOME"); // Stack var, shouldn't be freed
|
||||||
if (home_env != nullptr) return std::string(home_env);
|
if (home_env != nullptr) return std::string(home_env);
|
||||||
|
|
||||||
const struct passwd *pw = getpwuid(getuid());
|
const struct passwd *pw = getpwuid(getuid());
|
||||||
|
@ -840,7 +840,7 @@ void DetermineBasePaths(const char *exe)
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
const std::string homedir = GetHomeDir();
|
const std::string homedir = GetHomeDir();
|
||||||
#ifdef USE_XDG
|
#ifdef USE_XDG
|
||||||
const char *xdg_data_home = getenv("XDG_DATA_HOME");
|
const char *xdg_data_home = std::getenv("XDG_DATA_HOME");
|
||||||
if (xdg_data_home != nullptr) {
|
if (xdg_data_home != nullptr) {
|
||||||
tmp = xdg_data_home;
|
tmp = xdg_data_home;
|
||||||
tmp += PATHSEP;
|
tmp += PATHSEP;
|
||||||
|
@ -971,7 +971,7 @@ void DeterminePaths(const char *exe, bool only_local_path)
|
||||||
#ifdef USE_XDG
|
#ifdef USE_XDG
|
||||||
std::string config_home;
|
std::string config_home;
|
||||||
const std::string homedir = GetHomeDir();
|
const std::string homedir = GetHomeDir();
|
||||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
const char *xdg_config_home = std::getenv("XDG_CONFIG_HOME");
|
||||||
if (xdg_config_home != nullptr) {
|
if (xdg_config_home != nullptr) {
|
||||||
config_home = xdg_config_home;
|
config_home = xdg_config_home;
|
||||||
config_home += PATHSEP;
|
config_home += PATHSEP;
|
||||||
|
|
|
@ -1850,18 +1850,18 @@ const char *GetCurrentLocale(const char *param)
|
||||||
{
|
{
|
||||||
const char *env;
|
const char *env;
|
||||||
|
|
||||||
env = getenv("LANGUAGE");
|
env = std::getenv("LANGUAGE");
|
||||||
if (env != nullptr) return env;
|
if (env != nullptr) return env;
|
||||||
|
|
||||||
env = getenv("LC_ALL");
|
env = std::getenv("LC_ALL");
|
||||||
if (env != nullptr) return env;
|
if (env != nullptr) return env;
|
||||||
|
|
||||||
if (param != nullptr) {
|
if (param != nullptr) {
|
||||||
env = getenv(param);
|
env = std::getenv(param);
|
||||||
if (env != nullptr) return env;
|
if (env != nullptr) return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getenv("LANG");
|
return std::getenv("LANG");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const char *GetCurrentLocale(const char *param);
|
const char *GetCurrentLocale(const char *param);
|
||||||
|
|
Loading…
Reference in New Issue