diff options
author | Christopher Dumas <christopherdumas@gmail.com> | 2019-05-25 16:58:22 -0700 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-27 21:40:53 +0200 |
commit | 50154a23cbd51f72eeb199b8b56acfa8d7bb694a (patch) | |
tree | 9f11dc2454422cf4a59b35c78088f02b88306e7a /LibCore | |
parent | e3f81bce498523cc722524fc795f33e7d5c23c3e (diff) | |
download | serenity-50154a23cbd51f72eeb199b8b56acfa8d7bb694a.zip |
most apps now begin in the correct directory
Diffstat (limited to 'LibCore')
-rw-r--r-- | LibCore/CConfigFile.cpp | 12 | ||||
-rw-r--r-- | LibCore/CUserInfo.cpp | 17 | ||||
-rw-r--r-- | LibCore/CUserInfo.h | 1 | ||||
-rw-r--r-- | LibCore/Makefile | 3 |
4 files changed, 23 insertions, 10 deletions
diff --git a/LibCore/CConfigFile.cpp b/LibCore/CConfigFile.cpp index 1c4b108c71..e21014783c 100644 --- a/LibCore/CConfigFile.cpp +++ b/LibCore/CConfigFile.cpp @@ -1,5 +1,6 @@ #include <LibCore/CConfigFile.h> #include <LibCore/CFile.h> +#include <LibCore/CUserInfo.h> #include <AK/StringBuilder.h> #include <stdio.h> #include <pwd.h> @@ -7,15 +8,8 @@ Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name) { - String home_path; - if (auto* home_env = getenv("HOME")) { - home_path = home_env; - } else { - uid_t uid = getuid(); - if (auto* pwd = getpwuid(uid)) - home_path = pwd->pw_dir; - } - if (home_path.is_empty()) + String home_path = get_current_user_home_path(); + if (home_path == "/") home_path = String::format("/tmp"); auto path = String::format("%s/%s.ini", home_path.characters(), app_name.characters()); return adopt(*new CConfigFile(path)); diff --git a/LibCore/CUserInfo.cpp b/LibCore/CUserInfo.cpp new file mode 100644 index 0000000000..e297468fee --- /dev/null +++ b/LibCore/CUserInfo.cpp @@ -0,0 +1,17 @@ +#include "CUserInfo.h" +#include <stdlib.h> +#include <unistd.h> +#include <pwd.h> + +const char *get_current_user_home_path() { + if (auto* home_env = getenv("HOME")) { + return home_env; + } else { + auto d = "/"; + uid_t uid = getuid(); + if (auto* pwd = getpwuid(uid)) + return pwd->pw_dir; + else + return d; + } +} diff --git a/LibCore/CUserInfo.h b/LibCore/CUserInfo.h new file mode 100644 index 0000000000..22ef0a8fb4 --- /dev/null +++ b/LibCore/CUserInfo.h @@ -0,0 +1 @@ +const char *get_current_user_home_path(); diff --git a/LibCore/Makefile b/LibCore/Makefile index e6068b44ff..da0a92e3ca 100644 --- a/LibCore/Makefile +++ b/LibCore/Makefile @@ -19,7 +19,8 @@ OBJS = \ CConfigFile.o \ CEvent.o \ CProcessStatisticsReader.o \ - CDirIterator.o + CDirIterator.o \ + CUserInfo.o LIBRARY = libcore.a DEFINES += -DUSERLAND |