Do not retry failed close(3) in filesystem::copy
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Oct 2016 16:45:40 +0000 (17:45 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 24 Oct 2016 16:45:40 +0000 (17:45 +0100)
* src/filesystem/ops.cc (close_fd): Remove.
(do_copy_file): Just use close(3) instead of close_fd, to prevent
retrying on error.

From-SVN: r241485

libstdc++-v3/ChangeLog
libstdc++-v3/src/filesystem/ops.cc

index 112e941..577c88f 100644 (file)
@@ -1,5 +1,9 @@
 2016-10-24  Jonathan Wakely  <jwakely@redhat.com>
 
+       * src/filesystem/ops.cc (close_fd): Remove.
+       (do_copy_file): Just use close(3) instead of close_fd, to prevent
+       retrying on error.
+
        * src/filesystem/ops.cc (do_copy_file): Return an error if either
        source or destination is not a regular file.
        (copy): Update comment to refer to LWG 2681. Implement 2682 and 2683
index 6f76053..f8ba74e 100644 (file)
@@ -308,17 +308,6 @@ namespace
     return fs::file_time_type{seconds{s} + ns};
   }
 
-  // Returns true if the file descriptor was successfully closed,
-  // otherwise returns false and the reason will be in errno.
-  inline bool
-  close_fd(int fd)
-  {
-    while (::close(fd))
-      if (errno != EINTR)
-       return false;
-    return true;
-  }
-
   bool
   do_copy_file(const fs::path& from, const fs::path& to,
               fs::copy_options option,
@@ -405,8 +394,8 @@ namespace
       }
 
     struct CloseFD {
-      ~CloseFD() { if (fd != -1) close_fd(fd); }
-      bool close() { return close_fd(std::exchange(fd, -1)); }
+      ~CloseFD() { if (fd != -1) ::close(fd); }
+      bool close() { return ::close(std::exchange(fd, -1)) == 0; }
       int fd;
     };