summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/filesystem/src/posix_tools.hpp
diff options
context:
space:
mode:
authorrobot-contrib <[email protected]>2022-08-26 11:41:38 +0300
committerrobot-contrib <[email protected]>2022-08-26 11:41:38 +0300
commit76a1e556daf2542e3b3d55d7971cc1ed0abb1f50 (patch)
treec9603488e24fef3c6715a36b7962b27cb43f0c60 /contrib/restricted/boost/filesystem/src/posix_tools.hpp
parent559b3483fff94291f600c59ad6782cc6338d7dad (diff)
Update contrib/restricted/boost/filesystem and contrib/restricted/boost/io to 1.79.0
Diffstat (limited to 'contrib/restricted/boost/filesystem/src/posix_tools.hpp')
-rw-r--r--contrib/restricted/boost/filesystem/src/posix_tools.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/restricted/boost/filesystem/src/posix_tools.hpp b/contrib/restricted/boost/filesystem/src/posix_tools.hpp
new file mode 100644
index 00000000000..52426d4a36a
--- /dev/null
+++ b/contrib/restricted/boost/filesystem/src/posix_tools.hpp
@@ -0,0 +1,64 @@
+// posix_tools.hpp -------------------------------------------------------------------//
+
+// Copyright 2021 Andrey Semashev
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See library home page at http://www.boost.org/libs/filesystem
+
+//--------------------------------------------------------------------------------------//
+
+#ifndef BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_
+#define BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_
+
+#include "platform_config.hpp"
+#include <cerrno>
+#include <boost/filesystem/config.hpp>
+#ifdef BOOST_HAS_UNISTD_H
+#include <unistd.h>
+#endif
+
+namespace boost {
+namespace filesystem {
+namespace detail {
+
+/*!
+ * Closes a file descriptor and returns the result, similar to close(2). Unlike close(2), guarantees that the file descriptor is closed even if EINTR error happens.
+ *
+ * Some systems don't close the file descriptor in case if the thread is interrupted by a signal and close(2) returns EINTR.
+ * Other (most) systems do close the file descriptor even when when close(2) returns EINTR, and attempting to close it
+ * again could close a different file descriptor that was opened by a different thread. This function hides this difference in behavior.
+ *
+ * Future POSIX standards will likely fix this by introducing posix_close (see https://www.austingroupbugs.net/view.php?id=529)
+ * and prohibiting returning EINTR from close(2), but we still have to support older systems where this new behavior is not available and close(2)
+ * behaves differently between systems.
+ */
+inline int close_fd(int fd)
+{
+#if defined(hpux) || defined(_hpux) || defined(__hpux)
+ int res;
+ while (true)
+ {
+ res = ::close(fd);
+ if (BOOST_UNLIKELY(res < 0))
+ {
+ int err = errno;
+ if (err == EINTR)
+ continue;
+ }
+
+ break;
+ }
+
+ return res;
+#else
+ return ::close(fd);
+#endif
+}
+
+} // namespace detail
+} // namespace filesystem
+} // namespace boost
+
+#endif // BOOST_FILESYSTEM_SRC_POSIX_TOOLS_HPP_