always return wxString from wxGetUserHome() instead of char */wxWCharBuffer depending on the build
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1571,11 +1571,14 @@ that there isn't always a standard way to do a reliable check on the OS architec
|
||||
|
||||
\membersection{::wxGetUserHome}\label{wxgetuserhome}
|
||||
|
||||
\func{const wxChar *}{wxGetUserHome}{\param{const wxString\& }{user = ""}}
|
||||
\func{wxString}{wxGetUserHome}{\param{const wxString\& }{user = ""}}
|
||||
|
||||
Returns the home directory for the given user. If the username is empty
|
||||
Returns the home directory for the given user. If the \arg{user} is empty
|
||||
(default value), this function behaves like
|
||||
\helpref{wxGetHomeDir}{wxgethomedir}.
|
||||
\helpref{wxGetHomeDir}{wxgethomedir} i.e. returns the current user home
|
||||
directory.
|
||||
|
||||
If the home directory couldn't be determined, an empty string is returned.
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
|
@@ -522,13 +522,10 @@ WXDLLIMPEXP_BASE wxString wxGetUserName();
|
||||
WXDLLIMPEXP_BASE wxString wxGetHomeDir();
|
||||
WXDLLIMPEXP_BASE const wxChar* wxGetHomeDir(wxString *pstr);
|
||||
|
||||
// Get the user's home dir (caller must copy --- volatile)
|
||||
// returns NULL is no HOME dir is known
|
||||
#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WINE__)
|
||||
WXDLLIMPEXP_BASE const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
|
||||
#else
|
||||
WXDLLIMPEXP_BASE wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
|
||||
#endif
|
||||
// Get the user's (by default use the current user name) home dir,
|
||||
// return empty string on error
|
||||
WXDLLIMPEXP_BASE wxString wxGetUserHome(const wxString& user = wxEmptyString);
|
||||
|
||||
|
||||
#if wxUSE_LONGLONG
|
||||
typedef wxLongLong wxDiskspaceSize_t;
|
||||
|
@@ -589,10 +589,10 @@ wxString wxGetOsDescription()
|
||||
}
|
||||
|
||||
#ifndef __DARWIN__
|
||||
wxChar *wxGetUserHome (const wxString& user)
|
||||
wxString wxGetUserHome (const wxString& user)
|
||||
{
|
||||
// TODO
|
||||
return NULL;
|
||||
return wxString();
|
||||
}
|
||||
|
||||
bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
|
||||
|
@@ -211,14 +211,14 @@ const wxChar* wxGetHomeDir(wxString *home)
|
||||
return strDir.c_str();
|
||||
}
|
||||
|
||||
wxChar *wxGetUserHome(const wxString& user)
|
||||
wxString wxGetUserHome(const wxString& user)
|
||||
{
|
||||
static wxString home;
|
||||
wxString home;
|
||||
|
||||
if (user.empty() || user == wxGetUserId())
|
||||
return wx_const_cast(wxChar*, wxGetHomeDir(&home));
|
||||
else
|
||||
return _T("");
|
||||
wxGetHomeDir(&home);
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
// returns %UserName%, $USER or just "user"
|
||||
|
@@ -467,14 +467,14 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
||||
return strDir.c_str();
|
||||
}
|
||||
|
||||
wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
|
||||
wxString wxGetUserHome(const wxString& user)
|
||||
{
|
||||
// VZ: the old code here never worked for user != "" anyhow! Moreover, it
|
||||
// returned sometimes a malloc()'d pointer, sometimes a pointer to a
|
||||
// static buffer and sometimes I don't even know what.
|
||||
static wxString s_home;
|
||||
wxString home;
|
||||
|
||||
return (wxChar *)wxGetHomeDir(&s_home);
|
||||
if ( user.empty() || user == wxGetUserId() )
|
||||
wxGetHomeDir(&home);
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path),
|
||||
|
@@ -394,55 +394,45 @@ const wxChar* wxGetHomeDir(
|
||||
return rStrDir.c_str();
|
||||
}
|
||||
|
||||
// Hack for OS/2
|
||||
wxChar* wxGetUserHome ( const wxString &rUser )
|
||||
wxString wxGetUserHome ( const wxString &rUser )
|
||||
{
|
||||
wxChar* zHome;
|
||||
wxString sUser1(rUser);
|
||||
wxString sUser(rUser);
|
||||
|
||||
wxString home;
|
||||
|
||||
wxChar *wxBuffer = new wxChar[256];
|
||||
#ifndef __EMX__
|
||||
if (!sUser1.empty())
|
||||
if (!sUser.empty())
|
||||
{
|
||||
wxChar zTmp[64];
|
||||
const wxString currentUser = wxGetUserId();
|
||||
|
||||
if (wxGetUserId( zTmp
|
||||
,sizeof(zTmp)/sizeof(char)
|
||||
))
|
||||
{
|
||||
// Guests belong in the temp dir
|
||||
if (wxStricmp(zTmp, _T("annonymous")) == 0)
|
||||
if ( currentUser == "annonymous" )
|
||||
{
|
||||
if ((zHome = wxGetenv(_T("TMP"))) != NULL ||
|
||||
(zHome = wxGetenv(_T("TMPDIR"))) != NULL ||
|
||||
(zHome = wxGetenv(_T("TEMP"))) != NULL)
|
||||
delete[] wxBuffer;
|
||||
return *zHome ? zHome : (wxChar*)_T("\\");
|
||||
}
|
||||
if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0)
|
||||
sUser1 = wxEmptyString;
|
||||
zHome = wxGetenv(_T("TMP"));
|
||||
if ( !zHome )
|
||||
zHome = wxGetenv(_T("TMPDIR"));
|
||||
if ( !zHome )
|
||||
zHome = wxGetenv(_T("TEMP"));
|
||||
|
||||
if ( zHome && *zHome )
|
||||
return zHome;
|
||||
}
|
||||
|
||||
if ( sUser == currentUser )
|
||||
sUser.clear();
|
||||
}
|
||||
#endif
|
||||
if (sUser1.empty())
|
||||
if (sUser.empty())
|
||||
{
|
||||
if ((zHome = wxGetenv(_T("HOME"))) != NULL)
|
||||
{
|
||||
wxStrcpy(wxBuffer, zHome);
|
||||
wxUnix2DosFilename(wxBuffer);
|
||||
#if wxUSE_UNICODE
|
||||
wxWCharBuffer retBuffer (wxBuffer);
|
||||
delete[] wxBuffer;
|
||||
return retBuffer;
|
||||
#else
|
||||
wxStrcpy(zHome, wxBuffer);
|
||||
delete[] wxBuffer;
|
||||
return zHome;
|
||||
#endif
|
||||
home = zHome;
|
||||
home.Replace("/", "\\");
|
||||
}
|
||||
}
|
||||
delete[] wxBuffer;
|
||||
return (wxChar*)wxEmptyString; // No home known!
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
bool wxGetDiskSpace(const wxString& path,
|
||||
|
@@ -103,9 +103,9 @@ const wxChar* wxGetHomeDir(wxString *pstr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
|
||||
wxString wxGetUserHome(const wxString& WXUNUSED(user))
|
||||
{
|
||||
return NULL;
|
||||
return wxString();
|
||||
}
|
||||
|
||||
bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
|
||||
|
@@ -695,7 +695,7 @@ long wxExecute(wxChar **argv, int flags, wxProcess *process)
|
||||
|
||||
const wxChar* wxGetHomeDir( wxString *home )
|
||||
{
|
||||
*home = wxGetUserHome( wxEmptyString );
|
||||
*home = wxGetUserHome();
|
||||
wxString tmp;
|
||||
if ( home->empty() )
|
||||
*home = wxT("/");
|
||||
@@ -707,11 +707,7 @@ const wxChar* wxGetHomeDir( wxString *home )
|
||||
return home->c_str();
|
||||
}
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
const wxMB2WXbuf wxGetUserHome( const wxString &user )
|
||||
#else // just for binary compatibility -- there is no 'const' here
|
||||
char *wxGetUserHome( const wxString &user )
|
||||
#endif
|
||||
wxString wxGetUserHome( const wxString &user )
|
||||
{
|
||||
struct passwd *who = (struct passwd *) NULL;
|
||||
|
||||
@@ -721,20 +717,17 @@ char *wxGetUserHome( const wxString &user )
|
||||
|
||||
if ((ptr = wxGetenv(wxT("HOME"))) != NULL)
|
||||
{
|
||||
#if wxUSE_UNICODE
|
||||
wxWCharBuffer buffer( ptr );
|
||||
return buffer;
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
if ((ptr = wxGetenv(wxT("USER"))) != NULL || (ptr = wxGetenv(wxT("LOGNAME"))) != NULL)
|
||||
|
||||
if ((ptr = wxGetenv(wxT("USER"))) != NULL ||
|
||||
(ptr = wxGetenv(wxT("LOGNAME"))) != NULL)
|
||||
{
|
||||
who = getpwnam(wxSafeConvertWX2MB(ptr));
|
||||
}
|
||||
|
||||
// We now make sure the the user exists!
|
||||
if (who == NULL)
|
||||
// make sure the user exists!
|
||||
if ( !who )
|
||||
{
|
||||
who = getpwuid(getuid());
|
||||
}
|
||||
|
Reference in New Issue
Block a user