From 50bf39660fb28d2424b83bde73f9e4931ea1ff3a Mon Sep 17 00:00:00 2001 From: "Alexander S. Aganichev" Date: Mon, 26 Nov 2001 15:28:39 +0000 Subject: [PATCH] Fixed getlogin() usage --- goldlib/gall/gfilutl2.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/goldlib/gall/gfilutl2.cpp b/goldlib/gall/gfilutl2.cpp index c1c22d5..faf5de8 100644 --- a/goldlib/gall/gfilutl2.cpp +++ b/goldlib/gall/gfilutl2.cpp @@ -87,12 +87,17 @@ int strschg_environ(std::string& s) { #ifndef __HAVE_DRIVES__ if(not s.empty() and (s[0] == '~')) { std::string name; + char* lname; const char *p = s.c_str()+1; if((s.length() != 1) and not isslash(*p)) { while(*p and not isslash(*p)) name += *p++; - } else - name = getlogin(); + } + else { + if ((lname = getlogin()) == NULL) + lname = getenv("LOGNAME"); + name = lname; + } struct passwd *pe = getpwnam(name.c_str()); if(pe != NULL) { std::string dirname = pe->pw_dir; @@ -188,12 +193,16 @@ bool maketruepath(std::string &dirname) { #endif #else if(!dirname.empty() && (dirname[0] == '~')) { + char* lname; const char *p = dirname.c_str()+1; if((dirname.length() != 1) && !isslash(*p)) { while(*p && !isslash(*p)) ndirname += *p++; // get user name - } else - ndirname = getlogin(); // get current user name + } else { + if ((lname = getlogin()) == NULL) + lname = getenv("LOGNAME"); + ndirname = lname; // get current user name + } struct passwd *pe = getpwnam(ndirname.c_str()); // get home if(pe != NULL) { ndirname = pe->pw_dir;