From d3d968e5835f449d7ea715f45160db81ea906303 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 16 Aug 2022 20:29:54 +0200 Subject: [PATCH] Fix build on GNU/Hurd There is no path length limitation there, even via pathconf. But glibc provides a getcwd function that allocates the buffer dynamically so we can just leverage that. --- include/ghc/filesystem.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 9540b44..8cc504e 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -4199,6 +4199,13 @@ GHC_INLINE path current_path(std::error_code& ec) return path(); } return path(std::wstring(buffer.get()), path::native_format); +#elif defined(__GLIBC__) + std::unique_ptr buffer { ::getcwd(NULL, 0), std::free }; + if (buffer == nullptr) { + ec = detail::make_system_error(); + return path(); + } + return path(buffer.get()); #else size_t pathlen = static_cast(std::max(int(::pathconf(".", _PC_PATH_MAX)), int(PATH_MAX))); std::unique_ptr buffer(new char[pathlen + 1]);