X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aed08d7967af9365edd61723ca9fff977ca744c2..cdb105516c7934613e22c4ae2b0936ea77ad17ca:/src/common/filename.cpp?ds=sidebyside diff --git a/src/common/filename.cpp b/src/common/filename.cpp index db24f8040f..0e3653a6a3 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -434,6 +434,9 @@ void wxFileName::Clear() m_volume = m_name = m_ext = wxEmptyString; + + // we don't have any absolute path for now + m_relative = TRUE; } /* static */ @@ -634,19 +637,15 @@ 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"); -#if wxUSE_UNICODE - strcpy( buf, wxConvFile.cWC2MB( path ) ); -#else - strcpy( buf, path.c_str() ); -#endif - int fdTemp = mkstemp( buf ); + // we need to copy the path to the buffer in which mkstemp() can modify it + wxCharBuffer buf = wxConvFile.cWX2MB( path ); + + // cast is safe because the string length doesn't change + int fdTemp = mkstemp( (char*)(const char*) buf ); if ( fdTemp == -1 ) { // this might be not necessary as mkstemp() on most systems should have @@ -655,11 +654,8 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) } else // mkstemp() succeeded { -#if wxUSE_UNICODE - path = wxConvFile.cMB2WC( buf ); -#else - path = buf; -#endif + path = wxConvFile.cMB2WX( (const char*) buf ); + // avoid leaking the fd if ( fileTemp ) { @@ -676,22 +672,14 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // same as above path += _T("XXXXXX"); -#if wxUSE_UNICODE - strcpy( buf, wxConvFile.cWC2MB( path ) ); -#else - strcpy( buf, path.c_str() ); -#endif - if ( !mktemp( buf ) + wxCharBuffer buf = wxConvFile.cWX2MB( path ); + if ( !mktemp( (const char*) buf ) ) { path.clear(); } else { -#if wxUSE_UNICODE - path = wxConvFile.cMB2WC( buf ); -#else - path = buf; -#endif + path = wxConvFile.cMB2WX( (const char*) buf ); } #else // !HAVE_MKTEMP (includes __DOS__) // generate the unique file name ourselves @@ -1742,7 +1730,7 @@ public : m_type = from.m_type ; m_creator = from.m_creator ; } - MacDefaultExtensionRecord( char * extension , OSType type , OSType creator ) + MacDefaultExtensionRecord( const char * extension , OSType type , OSType creator ) { strncpy( m_ext , extension , kMacExtensionMaxLength ) ; m_ext[kMacExtensionMaxLength] = 0 ; @@ -1769,7 +1757,7 @@ static void MacEnsureDefaultExtensionsLoaded() { if ( !gMacDefaultExtensionsInited ) { - + // load the default extensions MacDefaultExtensionRecord defaults[1] = {