aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/StringUtil.cc34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index fa809be..19bc861 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -55,6 +55,12 @@
55 #include <errno.h> 55 #include <errno.h>
56#endif 56#endif
57 57
58#ifndef _WIN32
59#include <unistd.h>
60#include <sys/types.h>
61#include <pwd.h>
62#endif
63
58#include <memory> 64#include <memory>
59#include <algorithm> 65#include <algorithm>
60#include <string> 66#include <string>
@@ -109,6 +115,28 @@ int extractUnsignedNumber(const std::string& in, T& out) {
109} 115}
110 116
111 117
118std::string getHomePath() {
119
120 std::string home;
121 const char* h = NULL;
122#ifdef _WIN32
123 h = getenv("USERPROFILE");
124#else
125 h = getenv("HOME");
126#endif
127 if (h) {
128 home.assign(h);
129 } else {
130#ifndef _WIN32
131 uid_t uid = geteuid();
132 struct passwd* pw = getpwuid(uid);
133 if (pw) {
134 home.assign(pw->pw_dir);
135 }
136#endif
137 }
138 return home;
139}
112 140
113} 141}
114 142
@@ -240,11 +268,7 @@ string expandFilename(const string &filename) {
240 string retval; 268 string retval;
241 size_t pos = filename.find_first_not_of(" \t"); 269 size_t pos = filename.find_first_not_of(" \t");
242 if (pos != string::npos && filename[pos] == '~') { 270 if (pos != string::npos && filename[pos] == '~') {
243#ifdef _WIN32 271 retval = getHomePath();
244 retval = getenv("USERPROFILE");
245#else
246 retval = getenv("HOME");
247#endif
248 if (pos + 1 < filename.size()) { 272 if (pos + 1 < filename.size()) {
249 // copy from the character after '~' 273 // copy from the character after '~'
250 retval += static_cast<const char *>(filename.c_str() + pos + 1); 274 retval += static_cast<const char *>(filename.c_str() + pos + 1);