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
14 changes: 10 additions & 4 deletions src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf

use cpp::cpp;
use libc::{c_char, c_int, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
use libc::{c_char, c_int, fileno, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
use std::env;
use std::ptr;
use uucore::crash;

cpp! {{
#include <cstdio>
Expand Down Expand Up @@ -40,7 +39,10 @@ fn set_buffer(stream: *mut FILE, value: &str) {
input => {
let buff_size: usize = match input.parse() {
Ok(num) => num,
Err(e) => crash!(1, "incorrect size of buffer!: {}", e),
Err(_) => {
eprintln!("failed to allocate a {} byte stdio buffer", value);
std::process::exit(1);
}
};
(_IOFBF, buff_size as size_t)
}
Expand All @@ -52,7 +54,11 @@ fn set_buffer(stream: *mut FILE, value: &str) {
res = libc::setvbuf(stream, buffer, mode, size);
}
if res != 0 {
crash!(res, "error while calling setvbuf!");
eprintln!(
"could not set buffering of {} to mode {}",
unsafe { fileno(stream) },
cswn marked this conversation as resolved.
Show resolved Hide resolved
mode
);
}
}

Expand Down
Loading