00001
00002
00003 #include "ace/Dirent_Selector.h"
00004
00005 #if !defined (__ACE_INLINE__)
00006 #include "ace/Dirent_Selector.inl"
00007 #endif
00008
00009 #include "ace/OS_NS_dirent.h"
00010 #include "ace/OS_NS_stdlib.h"
00011
00012 ACE_RCSID (ace,
00013 Dirent_Selector,
00014 "Dirent_Selector.cpp,v 4.10 2006/02/10 10:05:58 jwillemsen Exp")
00015
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018
00019
00020 ACE_Dirent_Selector::ACE_Dirent_Selector (void)
00021 : namelist_ (0),
00022 n_ (0)
00023 {
00024 }
00025
00026 ACE_Dirent_Selector::~ACE_Dirent_Selector (void)
00027 {
00028
00029 this->close();
00030 }
00031
00032 int
00033 ACE_Dirent_Selector::open (const ACE_TCHAR *dir,
00034 int (*sel)(const ACE_DIRENT *d),
00035 int (*cmp) (const ACE_DIRENT **d1,
00036 const ACE_DIRENT **d2))
00037 {
00038 n_ = ACE_OS::scandir (dir, &this->namelist_, sel, cmp);
00039 return n_;
00040 }
00041
00042 int
00043 ACE_Dirent_Selector::close (void)
00044 {
00045 for (--n_; n_ >= 0; --n_)
00046 {
00047 #if defined (ACE_LACKS_STRUCT_DIR)
00048
00049
00050 ACE_OS::free (this->namelist_[n_]->d_name);
00051 #endif
00052 ACE_OS::free (this->namelist_[n_]);
00053 }
00054
00055 ACE_OS::free (this->namelist_);
00056 this->namelist_ = 0;
00057 return 0;
00058 }
00059
00060 ACE_END_VERSIONED_NAMESPACE_DECL