This commit is contained in:
mars 2023-04-11 23:57:29 -04:00
commit cc1debc051
3 changed files with 10 additions and 1 deletions

1
Cargo.lock generated
View File

@ -62,6 +62,7 @@ version = "0.1.0"
dependencies = [
"arg",
"crossterm",
"libc",
"once_cell",
"ropey",
"toml",

View File

@ -7,6 +7,7 @@ license = "AGPL-3.0-or-later"
[dependencies]
arg = "0.4.1"
crossterm = "0.26"
libc = "0.2.141"
once_cell = "1.17"
ropey = "1.6"
toml = "0.7"

View File

@ -354,7 +354,14 @@ fn main() -> Result<()> {
let mut buf = Vec::new();
match argv.get(1).map(|s| s.as_str()) {
Some("-") | None => unsafe { File::from_raw_fd(0) }, // stdin as a file
Some("-") | None => {
let stdin = 0; // get stdin as a file descriptor
if unsafe { libc::isatty(stdin) } == 0 {
unsafe { File::from_raw_fd(stdin) }
} else {
File::open("/dev/null").unwrap()
}
}
Some(path) => std::fs::File::open(path).unwrap_or_else(|_| {
eprintln!("{}: {}: No such file or directory.", argv[0], argv[1]);
exit(EX_UNAVAILABLE);