cat: refactor stdio handling#12210
Draft
xtqqczze wants to merge 1 commit into
Draft
Conversation
|
GNU testsuite comparison: |
c2a52d4 to
07699da
Compare
3 tasks
This comment was marked as outdated.
This comment was marked as outdated.
2736ee9 to
e95946e
Compare
Contributor
|
It is logically possible to |
This comment was marked as resolved.
This comment was marked as resolved.
Merging this PR will not alter performance
Comparing Footnotes
|
42e5ae2 to
a5a2281
Compare
xtqqczze
commented
May 13, 2026
| pub fn stdout_raw() -> StdoutRaw { | ||
| // SAFETY: We ensure that the file descriptor is never closed by | ||
| // wrapping the `File` in `ManuallyDrop`. | ||
| let fd = unsafe { rustix::stdio::take_stdout() }; |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| let fd = unsafe { rustix::stdio::take_stdout() }; | |
| let fd = unsafe { OwnedFd::from_raw_fd(libc::STDOUT_FILENO as RawFd) } |
We could avoid the rustix dependency here if so desired.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce safe wrappers for raw stdio backed by
ManuallyDrop<File>. TheManuallyDropprevents the file descriptor from being closed on drop, which could otherwise lead to undefined behavior.The wrapper only exposes
&FilefromStdinRaw, so safe code cannot take ownership and accidentally drop the underlying descriptor.