00001 // $Id: Dirent_Selector.cpp 73456 2006-07-11 21:42:19Z shuston $ 00002 00003 #include "ace/Dirent_Selector.h" 00004 00005 #if !defined (__ACE_INLINE__) 00006 #include "ace/Dirent_Selector.inl" 00007 #endif /* __ACE_INLINE__ */ 00008 00009 #include "ace/OS_NS_dirent.h" 00010 #include "ace/OS_NS_stdlib.h" 00011 00012 ACE_RCSID (ace, 00013 Dirent_Selector, 00014 "$Id: Dirent_Selector.cpp 73456 2006-07-11 21:42:19Z shuston $") 00015 00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 // Construction/Destruction 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 // Free up any allocated resources. 00029 this->close(); 00030 } 00031 00032 int 00033 ACE_Dirent_Selector::open (const ACE_TCHAR *dir, 00034 ACE_SCANDIR_SELECTOR sel, 00035 ACE_SCANDIR_COMPARATOR cmp) 00036 { 00037 n_ = ACE_OS::scandir (dir, &this->namelist_, sel, cmp); 00038 return n_; 00039 } 00040 00041 int 00042 ACE_Dirent_Selector::close (void) 00043 { 00044 for (--n_; n_ >= 0; --n_) 00045 { 00046 #if defined (ACE_LACKS_STRUCT_DIR) 00047 // Only the lacking-struct-dir emulation allocates this. Native 00048 // scandir includes d_name in the dirent struct itself. 00049 ACE_OS::free (this->namelist_[n_]->d_name); 00050 #endif 00051 ACE_OS::free (this->namelist_[n_]); 00052 } 00053 00054 ACE_OS::free (this->namelist_); 00055 this->namelist_ = 0; 00056 return 0; 00057 } 00058 00059 ACE_END_VERSIONED_NAMESPACE_DECL