Use glib functions instead of C functions for

wxDir. This works on the iPaq as well.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@22321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2003-07-27 22:11:44 +00:00
parent cb181d559c
commit 0d9f985f37

View File

@@ -36,10 +36,13 @@
#include "wx/dir.h"
#include "wx/filefn.h" // for wxMatchWild
#ifdef __WXGTK20__
#include "glib.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
// ----------------------------------------------------------------------------
@@ -64,13 +67,21 @@ public:
void SetFileSpec(const wxString& filespec) { m_filespec = filespec; }
void SetFlags(int flags) { m_flags = flags; }
#ifdef __WXGTK20__
void Rewind() { g_dir_rewind(m_dir); }
#else
void Rewind() { rewinddir(m_dir); }
#endif
bool Read(wxString *filename);
const wxString& GetName() const { return m_dirname; }
private:
#ifdef __WXGTK20__
GDir *m_dir;
#else
DIR *m_dir;
#endif
wxString m_dirname;
wxString m_filespec;
@@ -103,23 +114,36 @@ wxDirData::wxDirData(const wxString& dirname)
m_dirname.Truncate(n + 1);
// do open the dir
#ifdef __WXGTK20__
GError *error = NULL;
m_dir = g_dir_open( m_dirname.fn_str(), 0, &error );
#else
m_dir = opendir(m_dirname.fn_str());
#endif
}
wxDirData::~wxDirData()
{
if ( m_dir )
{
#ifdef __WXGTK20__
g_dir_close(m_dir);
#else
if ( closedir(m_dir) != 0 )
{
wxLogLastError(_T("closedir"));
}
#endif
}
}
bool wxDirData::Read(wxString *filename)
{
#ifdef __WXGTK20__
const char *de;
#else
dirent *de = (dirent *)NULL; // just to silence compiler warnings
#endif
bool matches = FALSE;
// speed up string concatenation in the loop a bit
@@ -128,23 +152,37 @@ bool wxDirData::Read(wxString *filename)
path.reserve(path.length() + 255);
wxString de_d_name;
while ( !matches )
{
de = readdir(m_dir);
#ifdef __WXGTK20__
de = g_dir_read_name( m_dir );
if ( !de )
return FALSE;
de_d_name = wxConvLibc.cMB2WC( de );
// don't return "." and ".." unless asked for
if ( de[0] == '.' &&
((de[1] == '.' && de[2] == '\0') ||
(de[1] == '\0')) )
#else
de = readdir(m_dir);
if ( !de )
return FALSE;
#if wxUSE_UNICODE
de_d_name = wxConvLibc.cMB2WC( de->d_name );
#else
de_d_name = de->d_name;
#endif
// don't return "." and ".." unless asked for
if ( de->d_name[0] == '.' &&
((de->d_name[1] == '.' && de->d_name[2] == '\0') ||
(de->d_name[1] == '\0')) )
#endif
{
if ( !(m_flags & wxDIR_DOTDOT) )
continue;
@@ -168,7 +206,11 @@ bool wxDirData::Read(wxString *filename)
// finally, check the name
if ( m_filespec.empty() )
{
#ifdef __WXGTK20__
matches = m_flags & wxDIR_HIDDEN ? TRUE : de[0] != '.';
#else
matches = m_flags & wxDIR_HIDDEN ? TRUE : de->d_name[0] != '.';
#endif
}
else
{