]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/src/filesystem/dir.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / filesystem / dir.cc
index 0738ea784f7ff7540aab3841d9b3c92a6a1af113..acc62986c68e5cb732d0632f86aeed5892ff0d82 100644 (file)
@@ -1,6 +1,6 @@
 // Class filesystem::directory_entry etc. -*- C++ -*-
 
-// Copyright (C) 2014-2019 Free Software Foundation, Inc.
+// Copyright (C) 2014-2021 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
 # define _GLIBCXX_USE_CXX11_ABI 1
 #endif
 
+#include <bits/largefile-config.h>
 #include <experimental/filesystem>
+
+#ifndef _GLIBCXX_HAVE_DIRENT_H
+# error "the <dirent.h> header is needed to build the Filesystem TS"
+#endif
+
 #include <utility>
 #include <stack>
 #include <string.h>
@@ -181,16 +187,16 @@ struct fs::recursive_directory_iterator::_Dir_stack : std::stack<_Dir>
 
 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
@@ -198,14 +204,18 @@ recursive_directory_iterator(const path& p, directory_options options,
       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());
     }
 }