From bf29b81a36383667f38e0daa15d8cbca0f7d7764 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Thu, 3 Oct 2024 13:26:18 +0300 Subject: [PATCH] Added a workaround for dirfd being a macro on FreeBSD 9 and older. Fixes https://github.com/boostorg/filesystem/issues/328. --- config/has_fdopendir_nofollow.cpp | 1 + doc/release_history.html | 1 + src/directory.cpp | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/has_fdopendir_nofollow.cpp b/config/has_fdopendir_nofollow.cpp index 0c8c268..0fe048f 100644 --- a/config/has_fdopendir_nofollow.cpp +++ b/config/has_fdopendir_nofollow.cpp @@ -16,6 +16,7 @@ int main() { int fd = open(".", O_DIRECTORY | O_RDONLY | O_NOFOLLOW); DIR* dir = fdopendir(fd); + // Note: dirfd is a macro on FreeBSD 9 and older int internal_fd = dirfd(dir); return dir != 0 && internal_fd >= 0; } diff --git a/doc/release_history.html b/doc/release_history.html index c7744ec..1cb4c37 100644 --- a/doc/release_history.html +++ b/doc/release_history.html @@ -46,6 +46,7 @@
  • On Windows, canonical is now based on the GetFinalPathNameByHandleW WinAPI function. As a side effect, drive letters are converted to upper case, which makes the resulting paths more interoperable. (#325)
  • v4: canonical no longer produces a trailing directory separator in the resulting path, if the input path has one.
  • If a path constructor or member function is called with an argument of a user-defined type that is convertible to path and one or more Source types, the conversion to path is now chosen by default. This may resolve argument conversion ambiguities in some cases, but may also result in a less optimal conversion path. If a different conversion path is desired, users are recommended to use explicit type casts. (#326)
  • +
  • Added a workaround for dirfd being a macro on FreeBSD 9 and older. (#328)
  • 1.86.0

    diff --git a/src/directory.cpp b/src/directory.cpp index bc5f62d..5cea59e 100644 --- a/src/directory.cpp +++ b/src/directory.cpp @@ -270,7 +270,8 @@ inline system::error_code dir_itr_close(dir_itr_imp& imp) noexcept // Obtains a file descriptor from the directory iterator inline int dir_itr_fd(dir_itr_imp const& imp, system::error_code& ec) { - int fd = ::dirfd(static_cast< DIR* >(imp.handle)); + // Note: dirfd is a macro on FreeBSD 9 and older + const int fd = dirfd(static_cast< DIR* >(imp.handle)); if (BOOST_UNLIKELY(fd < 0)) { int err = errno;