Try to get the user's home (~) from the env ($HOME) by default

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@966 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-02-21 16:40:14 +00:00
parent 3c5802271f
commit 46f6651ba1
+11 -3
View File
@@ -376,6 +376,8 @@ bool CZNC::IsHostAllowed(const CString& sHostMask) {
void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) {
char buf[PATH_MAX];
char *home;
if (getcwd(buf, PATH_MAX) == NULL) {
CUtils::PrintError("getcwd() failed, can't read my current dir");
exit(-1);
@@ -386,10 +388,16 @@ void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) {
m_sCurPath = (uPos == CString::npos) ? CString(buf) : CUtils::ChangeDir(buf, sArgvPath.substr(0, uPos), "");
// Try to set the user's home dir, default to binpath on failure
struct passwd* pUserInfo = getpwuid(getuid());
home = getenv("HOME");
if (pUserInfo) {
m_sHomePath = pUserInfo->pw_dir;
if (home) {
m_sHomePath = home;
} else {
struct passwd* pUserInfo = getpwuid(getuid());
if (pUserInfo) {
m_sHomePath = pUserInfo->pw_dir;
}
}
if (m_sHomePath.empty()) {