This fn is used just for avoiding overreading from stdin. But the unsafe can be logically removed by rustix's read syscall wrapper (at least on unix and wasi).
So we don't need have both of unexpected closing of fd and additional syscall overhead caused by clone.
|
/// Create a source from stdin using its raw file descriptor. |
|
/// |
|
/// This returns an instance of the `Source::StdinFile` variant, |
|
/// using the raw file descriptor of [`io::Stdin`] to create |
|
/// the [`File`] parameter. You can use this instead of |
|
/// `Source::Stdin` to allow reading from stdin without consuming |
|
/// the entire contents of stdin when this process terminates. |
|
#[cfg(unix)] |
|
fn stdin_as_file() -> Self { |
|
let fd = io::stdin().as_raw_fd(); |
|
let f = unsafe { File::from_raw_fd(fd) }; |
|
Self::StdinFile(f) |
|
} |
This fn is used just for avoiding overreading from stdin. But the unsafe can be logically removed by rustix's read syscall wrapper (at least on unix and wasi).
So we don't need have both of unexpected closing of fd and additional syscall overhead caused by clone.
coreutils/src/uu/dd/src/dd.rs
Lines 230 to 242 in f65350a