mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-10 18:48:54 +02:00
Fix logic error in file copy helper functions
If `errno` is `EAGAIN`, the second if statement is never true and if `errno` is not `EAGAIN`, the function returns immediately, not checking the second if statement. This commit fixes this. A logically equivalent change would have been to simply swap the two if statements but I find this version to be more readable.
This commit is contained in:
@@ -60,9 +60,9 @@ copy_with_sendfile(int infd, int outfd, off_t in_pos, size_t len, FastFileCopyBu
|
||||
off_t r = in_pos;
|
||||
ssize_t n = sendfile(outfd, infd, &r, len);
|
||||
if (n < 0) {
|
||||
if (errno != EAGAIN) return false;
|
||||
if (errno == EAGAIN) continue;
|
||||
if (errno == ENOSYS || errno == EPERM) return copy_with_buffer(infd, outfd, in_pos, len, fcb);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
if (n == 0) {
|
||||
// happens if input file is truncated
|
||||
@@ -83,9 +83,9 @@ copy_with_file_range(int infd, int outfd, off_t in_pos, size_t len, FastFileCopy
|
||||
off64_t r = in_pos;
|
||||
ssize_t n = copy_file_range(infd, &r, outfd, NULL, len, 0);
|
||||
if (n < 0) {
|
||||
if (errno != EAGAIN) return false;
|
||||
if (errno == EAGAIN) continue;
|
||||
if (errno == ENOSYS || errno == EPERM) return copy_with_sendfile(infd, outfd, in_pos, len, fcb);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
if (n == 0) {
|
||||
// happens if input file is truncated
|
||||
|
||||
Reference in New Issue
Block a user