| 1 | // | 
|---|---|
| 2 | // DirectoryIterator_UNIX.cpp | 
| 3 | // | 
| 4 | // Library: Foundation | 
| 5 | // Package: Filesystem | 
| 6 | // Module: DirectoryIterator | 
| 7 | // | 
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
| 9 | // and Contributors. | 
| 10 | // | 
| 11 | // SPDX-License-Identifier: BSL-1.0 | 
| 12 | // | 
| 13 | |
| 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 | |
| 23 | |
| 24 | namespace Poco { | 
| 25 | |
| 26 | |
| 27 | DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _pDir(0), _rc(1) | 
| 28 | { | 
| 29 | Path p(path); | 
| 30 | p.makeFile(); | 
| 31 | |
| 32 | #if defined(POCO_VXWORKS) | 
| 33 | _pDir = opendir(const_cast<char*>(p.toString().c_str())); | 
| 34 | #else | 
| 35 | _pDir = opendir(p.toString().c_str()); | 
| 36 | #endif | 
| 37 | if (!_pDir) File::handleLastError(path); | 
| 38 | |
| 39 | next(); | 
| 40 | } | 
| 41 | |
| 42 | |
| 43 | DirectoryIteratorImpl::~DirectoryIteratorImpl() | 
| 44 | { | 
| 45 | if (_pDir) closedir(_pDir); | 
| 46 | } | 
| 47 | |
| 48 | |
| 49 | const std::string& DirectoryIteratorImpl::next() | 
| 50 | { | 
| 51 | do | 
| 52 | { | 
| 53 | struct dirent* pEntry = readdir(_pDir); | 
| 54 | if (pEntry) | 
| 55 | _current = pEntry->d_name; | 
| 56 | else | 
| 57 | _current.clear(); | 
| 58 | } | 
| 59 | while (_current == "."|| _current == ".."); | 
| 60 | return _current; | 
| 61 | } | 
| 62 | |
| 63 | |
| 64 | } // namespace Poco | 
| 65 | 
