Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libstdbuf: remove crash macro #5565

Merged
merged 9 commits into from
Nov 30, 2023
13 changes: 7 additions & 6 deletions src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use cpp::cpp;
use libc::{c_char, c_int, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
use std::env;
use std::ptr;
use uucore::crash;
use uucore::error::USimpleError;
use uucore::show;

cpp! {{
#include <cstdio>
Expand Down Expand Up @@ -38,10 +39,10 @@ fn set_buffer(stream: *mut FILE, value: &str) {
"0" => (_IONBF, 0_usize),
"L" => (_IOLBF, 0_usize),
input => {
let buff_size: usize = match input.parse() {
Ok(num) => num,
Err(e) => crash!(1, "incorrect size of buffer!: {}", e),
};
let buff_size: usize = input
.parse()
.map_err(|e| format!("incorrect size of buffer!: {}", e))
.unwrap();
tertsdiepraam marked this conversation as resolved.
Show resolved Hide resolved
(_IOFBF, buff_size as size_t)
}
};
Expand All @@ -52,7 +53,7 @@ fn set_buffer(stream: *mut FILE, value: &str) {
res = libc::setvbuf(stream, buffer, mode, size);
}
if res != 0 {
crash!(res, "error while calling setvbuf!");
show!(USimpleError::new(res, "error while calling setvbuf!"));
}
}

Expand Down
Loading