diff --git a/profile/src/nsProfileAccess.cpp b/profile/src/nsProfileAccess.cpp index 95faa5a09dad..60aa9981345f 100644 --- a/profile/src/nsProfileAccess.cpp +++ b/profile/src/nsProfileAccess.cpp @@ -50,9 +50,11 @@ #if defined (XP_UNIX) #define USER_ENVIRONMENT_VARIABLE "USER" +#define LOGNAME_ENVIRONMENT_VARIABLE "LOGNAME" #define HOME_ENVIRONMENT_VARIABLE "HOME" #define PROFILE_NAME_ENVIRONMENT_VARIABLE "PROFILE_NAME" #define PROFILE_HOME_ENVIRONMENT_VARIABLE "PROFILE_HOME" +#define DEFAULT_UNIX_PROFILE_NAME "default" #elif defined (XP_BEOS) #endif @@ -1013,8 +1015,6 @@ nsProfileAccess::ProfileExists(const PRUnichar *profileName) nsresult nsProfileAccess::Get4xProfileInfo(const char *registryName) { - NS_ASSERTION(registryName, "Invalid registryName"); - nsresult rv = NS_OK; mNumOldProfiles = 0; @@ -1023,6 +1023,8 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName) if (NS_FAILED(rv)) return rv; #if defined(XP_PC) || defined(XP_MAC) + NS_ASSERTION(registryName, "Invalid registryName"); + nsCOMPtr oldReg(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = oldReg->Open(registryName); @@ -1118,16 +1120,20 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName) #elif defined (XP_BEOS) #else /* XP_UNIX */ - char *unixProfileName = PR_GetEnv(PROFILE_NAME_ENVIRONMENT_VARIABLE); - char *unixProfileDirectory = PR_GetEnv(PROFILE_HOME_ENVIRONMENT_VARIABLE); + nsCAutoString unixProfileName( PR_GetEnv(PROFILE_NAME_ENVIRONMENT_VARIABLE) ); + nsCAutoString unixProfileDirectory( PR_GetEnv(PROFILE_HOME_ENVIRONMENT_VARIABLE) ); - if (!unixProfileName || - !unixProfileDirectory || - (PL_strlen(unixProfileName) == 0) || - (PL_strlen(unixProfileDirectory) == 0)) + if (unixProfileName.IsEmpty() || + unixProfileDirectory.IsEmpty()) { - unixProfileName = PR_GetEnv(USER_ENVIRONMENT_VARIABLE); unixProfileDirectory = PR_GetEnv(HOME_ENVIRONMENT_VARIABLE); + unixProfileName = PR_GetEnv(LOGNAME_ENVIRONMENT_VARIABLE); + if ( unixProfileName.IsEmpty() ) { + unixProfileName = PR_GetEnv(USER_ENVIRONMENT_VARIABLE); + } + if ( unixProfileName.IsEmpty() ) { + unixProfileName = DEFAULT_UNIX_PROFILE_NAME; + } } PRBool exists = PR_FALSE;; @@ -1137,7 +1143,7 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName) return NS_OK; } - if (unixProfileName && unixProfileDirectory) { + if ( ! unixProfileName.IsEmpty() && ! unixProfileDirectory.IsEmpty() ) { nsCAutoString profileLocation(unixProfileDirectory); profileLocation += "/.netscape"; nsCOMPtr users4xDotNetscapeDirectory;