mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
expand: remove crash! macro
This commit is contained in:
parent
4a3efadf70
commit
46d4ebff4c
1 changed files with 6 additions and 9 deletions
|
@ -15,7 +15,7 @@ use std::str::from_utf8;
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{FromIo, UError, UResult};
|
use uucore::error::{FromIo, UError, UResult};
|
||||||
use uucore::{crash, format_usage, help_about, help_usage};
|
use uucore::{format_usage, help_about, help_usage};
|
||||||
|
|
||||||
const ABOUT: &str = help_about!("expand.md");
|
const ABOUT: &str = help_about!("expand.md");
|
||||||
const USAGE: &str = help_usage!("expand.md");
|
const USAGE: &str = help_usage!("expand.md");
|
||||||
|
@ -308,16 +308,13 @@ pub fn uu_app() -> Command {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(path: &str) -> BufReader<Box<dyn Read + 'static>> {
|
fn open(path: &str) -> std::io::Result<BufReader<Box<dyn Read + 'static>>> {
|
||||||
let file_buf;
|
let file_buf;
|
||||||
if path == "-" {
|
if path == "-" {
|
||||||
BufReader::new(Box::new(stdin()) as Box<dyn Read>)
|
Ok(BufReader::new(Box::new(stdin()) as Box<dyn Read>))
|
||||||
} else {
|
} else {
|
||||||
file_buf = match File::open(path) {
|
file_buf = File::open(path)?;
|
||||||
Ok(a) => a,
|
Ok(BufReader::new(Box::new(file_buf) as Box<dyn Read>))
|
||||||
Err(e) => crash!(1, "{}: {}\n", path.maybe_quote(), e),
|
|
||||||
};
|
|
||||||
BufReader::new(Box::new(file_buf) as Box<dyn Read>)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +375,7 @@ fn expand(options: &Options) -> std::io::Result<()> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
for file in &options.files {
|
for file in &options.files {
|
||||||
let mut fh = open(file);
|
let mut fh = open(file)?;
|
||||||
|
|
||||||
while match fh.read_until(b'\n', &mut buf) {
|
while match fh.read_until(b'\n', &mut buf) {
|
||||||
Ok(s) => s > 0,
|
Ok(s) => s > 0,
|
||||||
|
|
Loading…
Reference in a new issue