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/CUserInfo.cpp | |
parent | e3f81bce498523cc722524fc795f33e7d5c23c3e (diff) | |
download | serenity-50154a23cbd51f72eeb199b8b56acfa8d7bb694a.zip |
most apps now begin in the correct directory
Diffstat (limited to 'LibCore/CUserInfo.cpp')
-rw-r--r-- | LibCore/CUserInfo.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
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; + } +} |