DirectoryIterator_UNIX.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // DirectoryIterator_UNIX.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/DirectoryIterator_UNIX.cpp#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Filesystem
  8. // Module: DirectoryIterator
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/DirectoryIterator_UNIX.h"
  16. #if defined(POCO_VXWORKS)
  17. #include "Poco/File_VX.h"
  18. #else
  19. #include "Poco/File_UNIX.h"
  20. #endif
  21. #include "Poco/Path.h"
  22. namespace Poco {
  23. DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _pDir(0), _rc(1)
  24. {
  25. Path p(path);
  26. p.makeFile();
  27. #if defined(POCO_VXWORKS)
  28. _pDir = opendir(const_cast<char*>(p.toString().c_str()));
  29. #else
  30. _pDir = opendir(p.toString().c_str());
  31. #endif
  32. if (!_pDir) File::handleLastError(path);
  33. next();
  34. }
  35. DirectoryIteratorImpl::~DirectoryIteratorImpl()
  36. {
  37. if (_pDir) closedir(_pDir);
  38. }
  39. const std::string& DirectoryIteratorImpl::next()
  40. {
  41. do
  42. {
  43. struct dirent* pEntry = readdir(_pDir);
  44. if (pEntry)
  45. _current = pEntry->d_name;
  46. else
  47. _current.clear();
  48. }
  49. while (_current == "." || _current == "..");
  50. return _current;
  51. }
  52. } // namespace Poco