X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/401eb3dec29c09b9afcc843842cba48b33a5089b..41d368a4bb7a73fbc5ce054dbc205a57241cf0da:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index cac48112e5..c711152e64 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -638,9 +638,11 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // 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()); + // we need to copy the path to the buffer in which mkstemp() can modify it + wxCharBuffer buf(path.fn_str()); + + // cast is safe because the string length doesn't change + int fdTemp = mkstemp( (char *)buf.data() ); if ( fdTemp == -1 ) { // this might be not necessary as mkstemp() on most systems should have @@ -649,6 +651,8 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) } else // mkstemp() succeeded { + path = wxConvFile.cMB2WX(buf); + // avoid leaking the fd if ( fileTemp ) { @@ -665,10 +669,15 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // same as above path += _T("XXXXXX"); - if ( !mktemp((char *)path.mb_str()) ) + wxCharBuffer buf(path.fn_str()); + if ( !mktemp( buf ) ) { path.clear(); } + else + { + path = wxConvFile.cMB2WX(buf); + } #else // !HAVE_MKTEMP (includes __DOS__) // generate the unique file name ourselves #ifndef __DOS__ @@ -1660,7 +1669,7 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess, { #if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__)) wxStructStat stBuf; - if ( wxStat(GetFullPath().fn_str(), &stBuf) == 0 ) + if ( wxStat( GetFullPath().c_str(), &stBuf) == 0 ) { if ( dtAccess ) dtAccess->Set(stBuf.st_atime); @@ -1745,7 +1754,7 @@ static void MacEnsureDefaultExtensionsLoaded() { if ( !gMacDefaultExtensionsInited ) { - + // load the default extensions MacDefaultExtensionRecord defaults[1] = {