fs::recursive_directory_iterator::
recursive_directory_iterator(const path& p, directory_options options,
- error_code* ec)
+ error_code* ecptr)
: _M_options(options), _M_pending(true)
{
- if (ec)
- ec->clear();
if (posix::DIR* dirp = posix::opendir(p.c_str()))
{
+ if (ecptr)
+ ecptr->clear();
auto sp = std::make_shared<_Dir_stack>();
sp->push(_Dir{ dirp, p });
- if (sp->top().advance(ec))
+ if (ecptr ? sp->top().advance(*ecptr) : sp->top().advance())
_M_dirs.swap(sp);
}
else
const int err = errno;
if (err == EACCES
&& is_set(options, fs::directory_options::skip_permission_denied))
- return;
+ {
+ if (ecptr)
+ ecptr->clear();
+ return;
+ }
- if (!ec)
+ if (!ecptr)
_GLIBCXX_THROW_OR_ABORT(filesystem_error(
"recursive directory iterator cannot open directory", p,
std::error_code(err, std::generic_category())));
- ec->assign(err, std::generic_category());
+ ecptr->assign(err, std::generic_category());
}
}
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
+// { dg-do run { target c++11 } }
+// { dg-require-filesystem-ts "" }
+
+#include <experimental/filesystem>
+#include <cerrno>
+#include <testsuite_hooks.h>
+
+bool used_custom_readdir = false;
+
+extern "C" void* readdir(void*)
+{
+ used_custom_readdir = true;
+ errno = EIO;
+ return nullptr;
+}
+
+void
+test01()
+{
+ using std::experimental::filesystem::recursive_directory_iterator;
+ std::error_code ec;
+ recursive_directory_iterator it(".", ec);
+ if (used_custom_readdir)
+ VERIFY( ec.value() == EIO );
+}
+
+int
+main()
+{
+ test01();
+}