[libcxx-commits] [libcxx] [libc++] use copy_file_range for fs::copy (PR #109211)

Jannik Glückert via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 20 13:59:58 PDT 2024


Jannik2099 wrote:

Ok, I think this is ready for review now.

To summarize:

Add `copy_file_range` support on Linux and FreeBSD. `fs::copy_file` will first try `copy_file_range`, if unavailable and on linux `sendfile`, and finally the generic fstream.

This covers the following scenarios:

* `copy_file_range` is not implemented by the filesystem or the OS
* `copy_file_range` and/or `sendfile` are unable to copy to/from the source/dest in question
* `fs::copy_file` is used on a special linux zero-length file, such as those in `/proc` - this was previously unsupported.

I have also added a test for the `/proc` case, there are no such files on FreeBSD to my rudimentary knowledge, so the test is linux exclusive.

I am not super happy with how `copy_file_impl` looks now - it's stuck halfway between doing `#ifdef` on (effectively) the target OS, and halfway between doing it on the available syscalls. Feel free to tear apart.

https://github.com/llvm/llvm-project/pull/109211


More information about the libcxx-commits mailing list