Skip to content

Commit 79185fd

Browse files
ldionneJannik2099
authored andcommitted
Fix incorrect semantics
1 parent b697b46 commit 79185fd

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libcxx/src/filesystem/operations.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
// since Linux 4.5 and FreeBSD 13
4242
#if defined(__linux__) || defined(__FreeBSD__)
4343
# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
44-
#elif __has_include(<sys/sendfile.h>)
44+
#endif
45+
#if __has_include(<sys/sendfile.h>)
4546
# include <sys/sendfile.h>
4647
# define _LIBCPP_FILESYSTEM_USE_SENDFILE
4748
#elif defined(__APPLE__) || __has_include(<copyfile.h>)
@@ -277,8 +278,11 @@ bool copy_file_impl_sendfile(FileDescriptor& read_fd, FileDescriptor& write_fd,
277278
}
278279
#endif
279280

280-
#if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE)
281+
#if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE) || defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
282+
// If we have copy_file_range or sendfile, try both in succession (if available).
283+
// If both fail, fall back to using fstream.
281284
bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
285+
# if defined(_LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE)
282286
if (copy_file_impl_copy_file_range(read_fd, write_fd, ec)) {
283287
return true;
284288
}
@@ -299,10 +303,9 @@ bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_cod
299303
return false;
300304
}
301305
ec.clear();
302-
return copy_file_impl_fstream(read_fd, write_fd, ec);
303-
}
304-
#elif defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
305-
bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_code& ec) {
306+
# endif
307+
308+
# if defined(_LIBCPP_FILESYSTEM_USE_SENDFILE)
306309
if (copy_file_impl_sendfile(read_fd, write_fd, ec)) {
307310
return true;
308311
}
@@ -311,6 +314,8 @@ bool copy_file_impl(FileDescriptor& read_fd, FileDescriptor& write_fd, error_cod
311314
return false;
312315
}
313316
ec.clear();
317+
# endif
318+
314319
return copy_file_impl_fstream(read_fd, write_fd, ec);
315320
}
316321
#elif defined(_LIBCPP_FILESYSTEM_USE_COPYFILE)

0 commit comments

Comments
 (0)