mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
Use io::stdin() to read from standard input in a portable manner
This commit is contained in:
+7
-3
@@ -7,7 +7,7 @@ use crate::params::{parse_params, Format};
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::process::{exit, ExitCode};
|
||||
|
||||
mod context_diff;
|
||||
@@ -46,8 +46,12 @@ fn main() -> ExitCode {
|
||||
}
|
||||
// read files
|
||||
fn read_file_contents(filepath: &OsString) -> io::Result<Vec<u8>> {
|
||||
let stdin = OsString::from("/dev/stdin");
|
||||
fs::read(if filepath == "-" { &stdin } else { filepath })
|
||||
if filepath == "-" {
|
||||
let mut content = Vec::new();
|
||||
io::stdin().read_to_end(&mut content).and(Ok(content))
|
||||
} else {
|
||||
fs::read(filepath)
|
||||
}
|
||||
}
|
||||
let from_content = match read_file_contents(¶ms.from) {
|
||||
Ok(from_content) => from_content,
|
||||
|
||||
Reference in New Issue
Block a user