Skip to content

fast_io.rs: replace the unsafe libc::copy_file_range call by rustix#458

Open
Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix-#442-replace-unsafe-libc-function-by-rustix
Open

fast_io.rs: replace the unsafe libc::copy_file_range call by rustix#458
Franklin-Qi wants to merge 1 commit into
uutils:mainfrom
Franklin-Qi:fix-#442-replace-unsafe-libc-function-by-rustix

Conversation

@Franklin-Qi
Copy link
Copy Markdown

Replace the unsafe libc::copy_file_range call with the safe rustix::fs::copy_file_range
API to improve safety and reduce unsafe code surface.

Closes: #442

@Franklin-Qi Franklin-Qi changed the title Replace the unsafe libc::copy_file_range call by rustix fast_io.rs: replace the unsafe libc::copy_file_range call by rustix Jun 5, 2026
Replace the unsafe `libc::copy_file_range` call with the safe `rustix::fs::copy_file_range`.

Closes: uutils#442
@Franklin-Qi Franklin-Qi force-pushed the fix-#442-replace-unsafe-libc-function-by-rustix branch from 178f2d9 to 115b6b6 Compare June 5, 2026 08:10
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.29%. Comparing base (a9a332a) to head (115b6b6).

Files with missing lines Patch % Lines
src/sed/fast_io.rs 90.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #458      +/-   ##
==========================================
+ Coverage   82.18%   82.29%   +0.10%     
==========================================
  Files          13       13              
  Lines        5551     5585      +34     
  Branches      312      310       -2     
==========================================
+ Hits         4562     4596      +34     
  Misses        986      986              
  Partials        3        3              
Flag Coverage Δ
macos_latest 82.86% <ø> (ø)
ubuntu_latest 83.07% <90.00%> (+0.10%) ⬆️
windows_latest 0.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/sed/fast_io.rs
}

#[test]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_env isn't necessary

Comment thread src/sed/fast_io.rs
break;
let mut in_off_u64 = in_off as u64;
let result: std::io::Result<usize> = rustix_copy_file_range(
unsafe { BorrowedFd::borrow_raw(in_fd) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid these two unsafe ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review; I'll remove those two unsafe blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replace unsafe libc::copy_file_range by rustix

2 participants