[libcxx-commits] [libcxx] [libc++] Fix insufficiently guarded call to `copy_file_impl_fstream` (PR #214706)
Anthony Latsis via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 7 04:30:39 PDT 2026
https://github.com/AnthonyLatsis created https://github.com/llvm/llvm-project/pull/214706
copy_file_impl_fstream is only defined under
`_LIBCPP_FILESYSTEM_NEED_FSTREAM`, which additionally requires `_LIBCPP_HAS_LOCALIZATION`. The `_LIBCPP_FILESYSTEM_USE_FSTREAM` dispatch called it unconditionally, so a build with filesystem enabled and localization disabled failed on any platform that provides neither sendfile nor copyfile:
```
error: use of undeclared identifier 'copy_file_impl_fstream'
```
Report `EINVAL` instead, as the `sendfile`/`copy_file_range` dispatch above already does in the same situation.
Assisted-by: Claude Code
>From 424830c5b64c9648b547a8bdfb55c75cd2ce67fe Mon Sep 17 00:00:00 2001
From: Anthony Latsis <alatsis at apple.com>
Date: Fri, 7 Aug 2026 10:27:28 +0100
Subject: [PATCH] [libc++] Fix insufficiently guarded call to
`copy_file_impl_fstream`
copy_file_impl_fstream is only defined under
`_LIBCPP_FILESYSTEM_NEED_FSTREAM`, which additionally requires
`_LIBCPP_HAS_LOCALIZATION`. The `_LIBCPP_FILESYSTEM_USE_FSTREAM`
dispatch called it unconditionally, so a build with filesystem enabled
and localization disabled failed on any platform that provides neither
sendfile nor copyfile:
```
error: use of undeclared identifier 'copy_file_impl_fstream'
```
Report `EINVAL` instead, as the `sendfile`/`copy_file_range` dispatch
above already does in the same situation.
Assisted-by: Claude Code
---
libcxx/src/filesystem/operations.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 3ff62c102d0ad..7099cd2c75ab6 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -362,7 +362,13 @@ bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_cod
}
#elif defined(_LIBCPP_FILESYSTEM_USE_FSTREAM)
bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
+# if defined(_LIBCPP_FILESYSTEM_NEED_FSTREAM)
return copy_file_impl_fstream(read_fd, write_fd, ec);
+# else
+ // iostreams are unavailable in the no-locale build, just fail.
+ ec.assign(EINVAL, std::system_category());
+ return false;
+# endif
}
#else
# error "Unknown implementation for copy_file_impl"
More information about the libcxx-commits
mailing list