aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2013-06-29 06:39:02 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2013-06-29 06:39:02 (GMT)
commitf464f24eb3a5872404f60356009f466d5f79f2b1 (patch)
tree285557bd93d1f1825f21ced9766e1bcfeb2f90fc /src/FbTk
parent2efd4b823082efb45cb351c7185d510ccb1dd32a (diff)
downloadfluxbox-f464f24eb3a5872404f60356009f466d5f79f2b1.zip
fluxbox-f464f24eb3a5872404f60356009f466d5f79f2b1.tar.bz2
fix detection of $HOME folder
usually $HOME is set when fluxbox runs. in some rare scenarios (eg., fuzzying binaries to detect bugs) one could launch fluxbox by using 'env -i' and thus eliminating $HOME from the environment. to prevent crashes fluxbox uses now 'getpwuid()' when $HOME is not set to detect the home folder.
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);