X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2361ce822f82cd4964066319b2253562bf4de84b..59d04dff037f66e9e73b389de72835211f5f0bcd:/src/common/filename.cpp?ds=sidebyside diff --git a/src/common/filename.cpp b/src/common/filename.cpp index c097c399e1..70474e9b9e 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -124,6 +124,10 @@ #endif #endif +#ifdef __EMX__ +#define MAX_PATH _MAX_PATH +#endif + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -434,6 +438,9 @@ void wxFileName::Clear() m_volume = m_name = m_ext = wxEmptyString; + + // we don't have any absolute path for now + m_relative = TRUE; } /* static */ @@ -638,9 +645,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 *)path.mb_str()); + // 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 @@ -649,6 +658,8 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) } else // mkstemp() succeeded { + path = wxConvFile.cMB2WX( (const char*) buf ); + // avoid leaking the fd if ( fileTemp ) { @@ -665,10 +676,15 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) // same as above path += _T("XXXXXX"); - if ( !mktemp((char *)path.mb_str()) ) + wxCharBuffer buf = wxConvFile.cWX2MB( path ); + if ( !mktemp( (const char*) buf ) ) { path.clear(); } + else + { + path = wxConvFile.cMB2WX( (const char*) buf ); + } #else // !HAVE_MKTEMP (includes __DOS__) // generate the unique file name ourselves #ifndef __DOS__ @@ -912,6 +928,11 @@ bool wxFileName::Normalize(int flags, m_ext.MakeLower(); } + // we do have the path now + // + // NB: need to do this before (maybe) calling Assign() below + m_relative = FALSE; + #if defined(__WIN32__) if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) ) { @@ -919,9 +940,6 @@ bool wxFileName::Normalize(int flags, } #endif // Win32 - // we do have the path now - m_relative = FALSE; - return TRUE; } @@ -953,8 +971,8 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format) // get cwd only once - small time saving wxString cwd = wxGetCwd(); - Normalize(wxPATH_NORM_ALL, cwd, format); - fnBase.Normalize(wxPATH_NORM_ALL, cwd, format); + Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format); + fnBase.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format); bool withCase = IsCaseSensitive(format); @@ -1011,8 +1029,8 @@ bool wxFileName::SameAs(const wxFileName &filepath, wxPathFormat format) // get cwd only once - small time saving wxString cwd = wxGetCwd(); - fn1.Normalize(wxPATH_NORM_ALL, cwd, format); - fn2.Normalize(wxPATH_NORM_ALL, cwd, format); + fn1.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format); + fn2.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format); if ( fn1.GetFullPath() == fn2.GetFullPath() ) return TRUE; @@ -1344,7 +1362,13 @@ wxString wxFileName::GetLongPath() const WIN32_FIND_DATA findFileData; HANDLE hFind; - pathOut = wxEmptyString; + + if ( HasVolume() ) + pathOut = GetVolume() + + GetVolumeSeparator(wxPATH_DOS) + + GetPathSeparator(wxPATH_DOS); + else + pathOut = wxEmptyString; wxArrayString dirs = GetDirs(); dirs.Add(GetFullName()); @@ -1362,7 +1386,8 @@ wxString wxFileName::GetLongPath() const if ( tmpPath.empty() ) continue; - if ( tmpPath.Last() == wxT(':') ) + // can't see this being necessary? MF + if ( tmpPath.Last() == GetVolumeSeparator(wxPATH_DOS) ) { // Can't pass a drive and root dir to FindFirstFile, // so continue to next dir @@ -1374,8 +1399,12 @@ wxString wxFileName::GetLongPath() const hFind = ::FindFirstFile(tmpPath, &findFileData); if (hFind == INVALID_HANDLE_VALUE) { - // Error: return immediately with the original path - return path; + // Error: most likely reason is that path doesn't exist, so + // append any unprocessed parts and return + for ( i += 1; i < count; i++ ) + tmpPath += wxFILE_SEP_PATH + dirs[i]; + + return tmpPath; } pathOut += findFileData.cFileName; @@ -1599,7 +1628,7 @@ bool wxFileName::SetTimes(const wxDateTime *dtAccess, utimbuf utm; utm.actime = dtAccess ? dtAccess->GetTicks() : dtMod->GetTicks(); utm.modtime = dtMod ? dtMod->GetTicks() : dtAccess->GetTicks(); - if ( utime(GetFullPath(), &utm) == 0 ) + if ( utime(GetFullPath().fn_str(), &utm) == 0 ) { return TRUE; } @@ -1637,7 +1666,7 @@ bool wxFileName::Touch() { #if defined(__UNIX_LIKE__) // under Unix touching file is simple: just pass NULL to utime() - if ( utime(GetFullPath(), NULL) == 0 ) + if ( utime(GetFullPath().fn_str(), NULL) == 0 ) { return TRUE; } @@ -1658,7 +1687,7 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess, { #if defined(__UNIX_LIKE__) || defined(__WXMAC__) || (defined(__DOS__) && defined(__WATCOMC__)) wxStructStat stBuf; - if ( wxStat(GetFullPath(), &stBuf) == 0 ) + if ( wxStat( GetFullPath().c_str(), &stBuf) == 0 ) { if ( dtAccess ) dtAccess->Set(stBuf.st_atime); @@ -1716,7 +1745,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 ; @@ -1743,7 +1772,7 @@ static void MacEnsureDefaultExtensionsLoaded() { if ( !gMacDefaultExtensionsInited ) { - + // load the default extensions MacDefaultExtensionRecord defaults[1] = { @@ -1752,7 +1781,7 @@ static void MacEnsureDefaultExtensionsLoaded() } ; // we could load the pc exchange prefs here too - for ( int i = 0 ; i < WXSIZEOF( defaults ) ; ++i ) + for ( size_t i = 0 ; i < WXSIZEOF( defaults ) ; ++i ) { gMacDefaultExtensions.Add( defaults[i] ) ; }