#include <pwd.h>
#endif // !GDEF_OS_LINUX && !GDEF_OS_BSD && !GDEF_OS_MACOS
+static std::string getEnvVar( const char* name )
+{
+ const char *env = getenv( name );
+ env = env ? env : "";
+ std::string path( env );
+ return path;
+}
+
#if GDEF_OS_WINDOWS
static std::string getUserProfilePath();
#endif // !GDEF_OS_WINDOWS
static std::string getUserName()
{
#if GDEF_OS_WINDOWS
- std::string path( getenv( "USERNAME" ) );
+ std::string path = getEnvVar( "USERNAME" );
if ( ! path.empty() )
{
#endif // !GDEF_OS_WINDOWS
#if GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS
- std::string path( getenv( "USERNAME" ) );
+ std::string path = getEnvVar( "USERNAME" );
if ( ! path.empty() )
{
globalErrorStream() << "${USERNAME} not found, guessing…\n";
- path = std::string( getenv( "LOGNAME" ) );
+ path = getEnvVar( "LOGNAME" );
if ( ! path.empty() )
{
globalErrorStream() << "${LOGNAME} not found, guessing…\n";
- path = std::string( getenv( "USER" ) );
+ path = getEnvVar( "USER" );
if ( ! path.empty() )
{
static std::string getHomePath()
{
#if GDEF_OS_WINDOWS
- std::string path( getenv( "HOMEPATH" ) );
+ std::string path = getEnvVar( "HOMEPATH" );
if ( ! path.empty() )
{
#if GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS
// Get the path environment variable.
- std::string path( getenv( "HOME" ) );
+ std::string path = getEnvVar( "HOME" );
// Look up path directory in password database.
if( ! path.empty() )
#if GDEF_OS_WINDOWS
static std::string getSystemDrive()
{
- std::string path( getenv( "SYSTEMDRIVE" ) );
+ std::string path = getEnvVar( "SYSTEMDRIVE" );
if ( ! path.empty() )
{
static std::string getUserProfilePath()
{
- std::string path( getenv( "USERPROFILE" ) );
+ std::string path = getEnvVar( "USERPROFILE" );
if ( ! path.empty() )
{
static std::string getProgramFilesPath()
{
- std::string path( getenv( "ProgramFiles" ) );
+ std::string path = getEnvVar( "ProgramFiles" );
if ( ! path.empty() )
{
static std::string getProgramFilesX86Path()
{
- std::string path( getenv( "ProgramFiles(x86)" ) );
+ std::string path = getEnvVar( "ProgramFiles(x86)" );
if ( ! path.empty() )
{
static std::string getProgramW6432Path()
{
- std::string path( getenv( "ProgramW6432" ) );
+ std::string path = getEnvVar( "ProgramFilesW6432" );
if ( ! path.empty() )
{
static std::string getAppDataPath()
{
- std::string path( getenv( "APPDATA" ) );
+ std::string path = getEnvVar( "APPDATA" );
if ( ! path.empty() )
{
{
/* FIXME: we may want to rely on g_get_user_config_dir()
provided by GLib. */
- std::string path ( getenv( "XDG_CONFIG_HOME" ) );
+
+ std::string path = getEnvVar( "XDG_CONFIG_HOME" );
if ( ! path.empty() )
{
static std::string getXdgDataHomePath()
{
- std::string path ( getenv( "XDG_DATA_HOME" ) );
+ std::string path = getEnvVar( "XDG_DATA_HOME" );
if ( ! path.empty() )
{