ClickHouse/base/poco/Foundation/src/DirectoryIterator_UNIX.cpp
2023-02-14 22:09:58 +00:00

57 lines
931 B
C++

//
// DirectoryIterator_UNIX.cpp
//
// Library: Foundation
// Package: Filesystem
// Module: DirectoryIterator
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/DirectoryIterator_UNIX.h"
#include "Poco/File_UNIX.h"
#include "Poco/Path.h"
namespace Poco {
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _pDir(0), _rc(1)
{
Path p(path);
p.makeFile();
_pDir = opendir(p.toString().c_str());
if (!_pDir) File::handleLastError(path);
next();
}
DirectoryIteratorImpl::~DirectoryIteratorImpl()
{
if (_pDir) closedir(_pDir);
}
const std::string& DirectoryIteratorImpl::next()
{
do
{
struct dirent* pEntry = readdir(_pDir);
if (pEntry)
_current = pEntry->d_name;
else
_current.clear();
}
while (_current == "." || _current == "..");
return _current;
}
} // namespace Poco