From: Robert Roebling <robert@roebling.de>
Date: Sat, 10 Aug 2002 14:41:37 +0000 (+0000)
Subject:   (char*)(const char*)xxx.mb_str()  is not a good
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/aed08d7967af9365edd61723ca9fff977ca744c2

  (char*)(const char*)xxx.mb_str()  is not a good
    thing under Unicode.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16443 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/src/common/filename.cpp b/src/common/filename.cpp
index b639fda809..db24f8040f 100644
--- a/src/common/filename.cpp
+++ b/src/common/filename.cpp
@@ -634,13 +634,19 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
 
     path += name;
 
+    // Needed for Unicode/Ansi conversion
+    char buf[500];
+    
 #if defined(HAVE_MKSTEMP)
     // scratch space for mkstemp()
     path += _T("XXXXXX");
 
-    // can use the cast here because the length doesn't change and the string
-    // is not shared
-    int fdTemp = mkstemp((char*)(const char *)path.mb_str());
+#if wxUSE_UNICODE
+    strcpy( buf, wxConvFile.cWC2MB( path ) );
+#else
+    strcpy( buf, path.c_str() );
+#endif
+    int fdTemp = mkstemp( buf );
     if ( fdTemp == -1 )
     {
         // this might be not necessary as mkstemp() on most systems should have
@@ -649,6 +655,11 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
     }
     else // mkstemp() succeeded
     {
+#if wxUSE_UNICODE
+        path = wxConvFile.cMB2WC( buf );
+#else
+        path = buf;
+#endif
         // avoid leaking the fd
         if ( fileTemp )
         {
@@ -665,10 +676,23 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
     // same as above
     path += _T("XXXXXX");
 
-    if ( !mktemp((char *)path.mb_str()) )
+#if wxUSE_UNICODE
+    strcpy( buf, wxConvFile.cWC2MB( path ) );
+#else
+    strcpy( buf, path.c_str() );
+#endif
+    if ( !mktemp( buf )
     {
         path.clear();
     }
+    else
+    {
+#if wxUSE_UNICODE
+        path = wxConvFile.cMB2WC( buf );
+#else
+        path = buf;
+#endif
+    }
 #else // !HAVE_MKTEMP (includes __DOS__)
     // generate the unique file name ourselves
     #ifndef __DOS__