Fallback from sendfile64() in case of ENOSYS as well

As suggested on https://man7.org/linux/man-pages/man2/sendfile.2.html.
This commit is contained in:
Martchus 2023-04-23 21:04:31 +02:00
parent da91e54ec7
commit a55a3604bd
1 changed files with 2 additions and 2 deletions

View File

@ -114,7 +114,7 @@ template <std::size_t bufferSize> void CopyHelper<bufferSize>::copy(NativeFileSt
while (count) {
const auto bytesCopied = ::sendfile64(output.fileDescriptor(), input.fileDescriptor(), nullptr, count);
if (bytesCopied < 0) {
if (errno == EINVAL && static_cast<std::uint64_t>(totalBytes) == count) {
if ((errno == EINVAL || errno == ENOSYS) && static_cast<std::uint64_t>(totalBytes) == count) {
// try again the unoptimized version, maybe the filesystem doesn't support sendfile
goto unoptimized_version;
}
@ -163,7 +163,7 @@ void CopyHelper<bufferSize>::callbackCopy(NativeFileStream &input, NativeFileStr
const auto bytesToCopy = static_cast<std::size_t>(std::min(count, static_cast<std::uint64_t>(bufferSize)));
const auto bytesCopied = ::sendfile64(output.fileDescriptor(), input.fileDescriptor(), nullptr, bytesToCopy);
if (bytesCopied < 0) {
if (errno == EINVAL && static_cast<std::uint64_t>(totalBytes) == count) {
if ((errno == EINVAL || errno == ENOSYS) && static_cast<std::uint64_t>(totalBytes) == count) {
// try again the unoptimized version, maybe the filesystem doesn't support sendfile
goto unoptimized_version;
}