]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dir.cpp
fixed crash on invalid data (patch 1039453)
[wxWidgets.git] / src / os2 / dir.cpp
index c5a14f2ce3494faeb1e849af0f7293b15b02df6b..9bb20871624a703e86945058e82b061dc11c4581 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     08.12.99
 // RCS-ID:      $Id$
 // Copyright:   (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -25,6 +25,7 @@
 #include "wx/wxprec.h"
 
 #ifndef WX_PRECOMP
+    #include "wx/os2/private.h"
     #include "wx/intl.h"
     #include "wx/log.h"
 #endif // PCH
@@ -35,6 +36,7 @@
 #include <sys/types.h>
 
 #define INCL_DOSFILEMGR
+#define INCL_DOSERRORS
 #include <os2.h>
 
 #ifdef __EMX__
@@ -74,19 +76,19 @@ static inline FIND_DATA FindFirst(
 )
 {
     ULONG                       ulFindCount = 1;
-    FIND_DATA                   hDir;
+    FIND_DATA                   hDir = HDIR_CREATE;
     FIND_ATTR                   rc;
 
     rc = ::DosFindFirst( rsSpec.c_str()
                         ,&hDir
-                        ,FILE_NORMAL
+                       ,0x37 // was: FILE_NORMAL
                         ,pFinddata
                         ,sizeof(FILEFINDBUF3)
                         ,&ulFindCount
                         ,FIL_STANDARD
                        );
     if (rc != 0)
-        return 0;
+        return InitFindData();
     return hDir;
 }
 
@@ -101,7 +103,7 @@ static inline bool FindNext(
                          ,pFinddata
                          ,sizeof(FILEFINDBUF3)
                          ,&ulFindCount
-                         ) != 0;
+                         ) == 0;
 }
 
 static const wxChar* GetNameFromFindData(
@@ -160,6 +162,7 @@ public:
     void SetFileSpec(const wxString& rsFilespec) { m_sFilespec = rsFilespec; }
     void SetFlags(int nFlags) { m_nFlags = nFlags; }
 
+    const wxString& GetName() const { return m_sDirname; }
     void Close();
     void Rewind();
     bool Read(wxString* rsFilename);
@@ -348,6 +351,28 @@ bool wxDir::IsOpened() const
     return m_data != NULL;
 } // end of wxDir::IsOpen
 
+wxString wxDir::GetName() const
+{
+    wxString name;
+    if ( m_data )
+    {
+        name = M_DIR->GetName();
+        if ( !name.empty() )
+        {
+            // bring to canonical Windows form
+            name.Replace(_T("/"), _T("\\"));
+
+            if ( name.Last() == _T('\\') )
+            {
+                // chop off the last (back)slash
+                name.Truncate(name.length() - 1);
+            }
+        }
+    }
+
+    return name;
+}
+
 wxDir::~wxDir()
 {
     delete M_DIR;