From bf41330551a76ea426ace38dbc57c333ef5112cc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 27 Feb 2017 19:49:39 +0300 Subject: Add function for get home path. --- src/fs/paths.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/fs/paths.cpp') diff --git a/src/fs/paths.cpp b/src/fs/paths.cpp index affc12285..aa1c453b0 100644 --- a/src/fs/paths.cpp +++ b/src/fs/paths.cpp @@ -47,6 +47,11 @@ #include #endif // WIN32 +#ifndef WIN32 +#include +#include +#endif // WIN32 + #ifdef ANDROID #ifdef USE_SDL2 #include @@ -203,6 +208,33 @@ std::string getPicturesDir() #endif // WIN32 } +std::string getHomePath() +{ +#ifdef WIN32 + return getSpecialFolderLocation(CSIDL_LOCAL_APPDATA); +#else + const char *path = getenv("HOME"); + if (path == nullptr) + { + uid_t uid = getuid(); + struct passwd *pw; + + pw = getpwuid(uid); + if (pw != NULL && + pw->pw_dir != nullptr) + { + path = pw->pw_dir; + } + if (path == nullptr) + return "/"; + } + std::string dir = path; + if (findLast(dir, "/") == false) + dir += "/"; + return dir; +#endif // WIN32 +} + #ifdef ANDROID std::string getSdStoragePath() { -- cgit v1.2.3-70-g09d2