]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filename.cpp
Fix unintialized pointer in wxCommandProcessor when
[wxWidgets.git] / src / common / filename.cpp
index f56ec3d5ef0829e639c9c7eb11275c2497773473..a5a5f853a820aaee3e2b000c9e1f5adb71b053d7 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     28.12.2000
 // RCS-ID:      $Id$
 // Copyright:   (c) 2000 Robert Roebling
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 /*
 
 // For GetShort/LongPathName
 #ifdef __WIN32__
-#include <windows.h>
-#include "wx/msw/winundef.h"
+#include "wx/msw/wrapwin.h"
+#endif
+
+#ifdef __WXWINCE__
+#include "wx/msw/private.h"
 #endif
 
 #if defined(__WXMAC__)
 #endif
 
 #ifdef __MWERKS__
+#ifdef __MACH__
+#include <sys/types.h>
+#include <utime.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#else
 #include <stat.h>
 #include <unistd.h>
 #include <unix.h>
 #endif
+#endif
 
 #ifdef __WATCOMC__
 #include <io.h>
@@ -194,7 +204,7 @@ private:
 // private functions
 // ----------------------------------------------------------------------------
 
-#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+#if wxUSE_DATETIME && defined(__WIN32__) && !defined(__WXMICROWIN__)
 
 // convert between wxDateTime and FILETIME which is a 64-bit value representing
 // the number of 100-nanosecond intervals since January 1, 1601.
@@ -241,7 +251,7 @@ static void ConvertWxToFileTime(FILETIME *ft, const wxDateTime& dt)
     }
 }
 
-#endif // __WIN32__
+#endif // wxUSE_DATETIME && __WIN32__
 
 // return a string with the volume par
 static wxString wxGetVolumeString(const wxString& volume, wxPathFormat format)
@@ -444,16 +454,16 @@ void wxFileName::Clear()
 }
 
 /* static */
-wxFileName wxFileName::FileName(const wxString& file)
+wxFileName wxFileName::FileName(const wxString& file, wxPathFormat format)
 {
-    return wxFileName(file);
+    return wxFileName(file, format);
 }
 
 /* static */
-wxFileName wxFileName::DirName(const wxString& dir)
+wxFileName wxFileName::DirName(const wxString& dir, wxPathFormat format)
 {
     wxFileName fn;
-    fn.AssignDir(dir);
+    fn.AssignDir(dir, format);
     return fn;
 }
 
@@ -461,7 +471,7 @@ wxFileName wxFileName::DirName(const wxString& dir)
 // existence tests
 // ----------------------------------------------------------------------------
 
-bool wxFileName::FileExists()
+bool wxFileName::FileExists() const
 {
     return wxFileName::FileExists( GetFullPath() );
 }
@@ -471,7 +481,7 @@ bool wxFileName::FileExists( const wxString &file )
     return ::wxFileExists( file );
 }
 
-bool wxFileName::DirExists()
+bool wxFileName::DirExists() const
 {
     return wxFileName::DirExists( GetFullPath() );
 }
@@ -557,8 +567,22 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
     // use the directory specified by the prefix
     SplitPath(prefix, &dir, &name, NULL /* extension */);
 
-#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
+#if defined(__WXWINCE__)
+    if (dir.empty())
+    {
+        // FIXME. Create \temp dir?
+        dir = wxT("\\");
+    }
+    path = dir + wxT("\\") + prefix;
+    int i = 1;
+    while (wxFileExists(path))
+    {
+        path = dir + wxT("\\") + prefix ;
+        path << i;
+        i ++;
+    }
 
+#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
 #ifdef __WIN32__
     if ( dir.empty() )
     {
@@ -687,7 +711,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
     }
 #else // !HAVE_MKTEMP (includes __DOS__)
     // generate the unique file name ourselves
-    #ifndef __DOS__
+    #if !defined(__DOS__) && (!defined(__MWERKS__) || defined(__DARWIN__) )
     path << (unsigned int)getpid();
     #endif
 
@@ -776,7 +800,14 @@ bool wxFileName::Mkdir( const wxString& dir, int perm, int flags )
         size_t count = dirs.GetCount();
         for ( size_t i = 0; i < count; i++ )
         {
-            if ( i > 0 || filename.IsAbsolute() )
+            if ( i > 0 || 
+#if defined(__WXMAC__) && !defined(__DARWIN__)
+                       // relative pathnames are exactely the other way round under mac...
+               !filename.IsAbsolute() 
+#else
+               filename.IsAbsolute() 
+#endif
+            )
                 currPath += wxFILE_SEP_PATH;
             currPath += dirs[i];
 
@@ -967,7 +998,7 @@ bool wxFileName::IsAbsolute(wxPathFormat format) const
 
 bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
 {
-    wxFileName fnBase(pathBase, format);
+    wxFileName fnBase = wxFileName::DirName(pathBase, format);
 
     // get cwd only once - small time saving
     wxString cwd = wxGetCwd();
@@ -1126,7 +1157,7 @@ void wxFileName::InsertDir( int before, const wxString &dir )
 
 void wxFileName::RemoveDir( int pos )
 {
-    m_dirs.Remove( (size_t)pos );
+    m_dirs.RemoveAt( (size_t)pos );
 }
 
 // ----------------------------------------------------------------------------
@@ -1270,7 +1301,7 @@ wxString wxFileName::GetFullPath( wxPathFormat format ) const
 // Return the short form of the path (returns identity on non-Windows platforms)
 wxString wxFileName::GetShortPath() const
 {
-#if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__)
+#if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
     wxString path(GetFullPath());
     wxString pathOut;
     DWORD sz = ::GetShortPathName(path, NULL, 0);
@@ -1612,6 +1643,8 @@ void wxFileName::SplitPath(const wxString& fullpath,
 // time functions
 // ----------------------------------------------------------------------------
 
+#if wxUSE_DATETIME
+
 bool wxFileName::SetTimes(const wxDateTime *dtAccess,
                           const wxDateTime *dtMod,
                           const wxDateTime *dtCreate)
@@ -1760,6 +1793,8 @@ bool wxFileName::GetTimes(wxDateTime *dtAccess,
     return FALSE;
 }
 
+#endif // wxUSE_DATETIME
+
 #ifdef __WXMAC__
 
 const short kMacExtensionMaxLength = 16 ;
@@ -1773,18 +1808,18 @@ public :
   }
   MacDefaultExtensionRecord( const MacDefaultExtensionRecord& from )
   {
-    strcpy( m_ext , from.m_ext ) ;
+    wxStrcpy( m_ext , from.m_ext ) ;
     m_type = from.m_type ;
     m_creator = from.m_creator ;
   }
-  MacDefaultExtensionRecord( const char * extension , OSType type , OSType creator )
+  MacDefaultExtensionRecord( const wxChar * extension , OSType type , OSType creator )
   {
-    strncpy( m_ext , extension , kMacExtensionMaxLength ) ;
+    wxStrncpy( m_ext , extension , kMacExtensionMaxLength ) ;
     m_ext[kMacExtensionMaxLength] = 0 ;
     m_type = type ;
     m_creator = creator ;
   }
-  char m_ext[kMacExtensionMaxLength] ;
+  wxChar m_ext[kMacExtensionMaxLength] ;
   OSType m_type ;
   OSType m_creator ;
 }  ;
@@ -1808,7 +1843,7 @@ static void MacEnsureDefaultExtensionsLoaded()
     // load the default extensions
     MacDefaultExtensionRecord defaults[1] =
     {
-      MacDefaultExtensionRecord( "txt" , 'TEXT' , 'ttxt' ) ,
+      MacDefaultExtensionRecord( wxT("txt") , 'TEXT' , 'ttxt' ) ,
 
     } ;
     // we could load the pc exchange prefs here too
@@ -1880,7 +1915,7 @@ void wxFileName::MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint3
   MacDefaultExtensionRecord rec ;
   rec.m_type = type ;
   rec.m_creator = creator ;
-  strncpy( rec.m_ext , ext.Lower().c_str() , kMacExtensionMaxLength ) ;
+  wxStrncpy( rec.m_ext , ext.Lower().c_str() , kMacExtensionMaxLength ) ;
   gMacDefaultExtensions.Add( rec ) ;
 }
 #endif