]> git.saurik.com Git - wxWidgets.git/commitdiff
always return wxString from wxGetUserHome() instead of char */wxWCharBuffer depending...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Oct 2007 12:38:15 +0000 (12:38 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 Oct 2007 12:38:15 +0000 (12:38 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/function.tex
include/wx/utils.h
src/mac/carbon/utils.cpp
src/msdos/utilsdos.cpp
src/msw/utils.cpp
src/os2/utils.cpp
src/palmos/utils.cpp
src/unix/utilsunx.cpp

index 62e622480a7a966064856df4b84fdc0b668acc9e..5ab7cee273bde988506eaf614f01b0367b9db2e4 100644 (file)
@@ -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
-(default value), this function behaves like
-\helpref{wxGetHomeDir}{wxgethomedir}.
+Returns the home directory for the given user. If the \arg{user} is empty
+(default value), this function behaves like 
+\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}
 
index f63fae9c3c7b2c0e91e8e70a7b04dc4638fa0b30..6fe085107570640e3c0a652a80bc7e3b21615dde 100644 (file)
@@ -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;
@@ -550,7 +547,7 @@ typedef int (wxCMPFUNC_CONV *CMPFUNCDATA)(const void* pItem1, const void* pItem2
 
 
 WXDLLIMPEXP_BASE void wxQsort(void *const pbase, size_t total_elems,
-                                          size_t size, CMPFUNCDATA cmp, const void* user_data);
+                              size_t size, CMPFUNCDATA cmp, const void* user_data);
 
 
 #if wxUSE_GUI // GUI only things from now on
index 55848f5799b23fec313a5f5d39c645d5b60689ad..71acf7553defe8e93de9174f02bf161f4b7e9a57 100644 (file)
@@ -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)
index 6f432f4f89f0063da418a9cd9b4f5a76cc11768e..ff4647668c0a9df96f65fbcede49785be908e43f 100644 (file)
@@ -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"
index baeeb9e5b79a2c59332784a3eeb16096b3b1805d..fb792f42b3bd1ebfabc12be67f7a943e68f58709 100644 (file)
@@ -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),
index 142878fd26feec4fa6ee7b69c7e84214db4f2390..e3bc440f2714d8cafe12dd5a4bf423ce4f7a36c6 100644 (file)
@@ -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 ( currentUser == "annonymous" )
         {
-            // Guests belong in the temp dir
-            if (wxStricmp(zTmp, _T("annonymous")) == 0)
-            {
-                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,
index c8d8d849088c24b76fea28d52e80ba403c581343..e0da4651b1d7fe4acc1bf2992c5eaa6be0681e4e 100644 (file)
@@ -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)
index 429cf3e2f3c13824af43b45c0d6427747a7dd659..1cdeb6e6706eb1a70c6d883fa43572fefec46117 100644 (file)
@@ -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());
         }