Skip to content

Commit

Permalink
libstdbuf: remove uucore macro/struct and use gnu messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cswn committed Nov 23, 2023
1 parent 0a320ea commit 1761a7d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use cpp::cpp;
use libc::{c_char, c_int, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
use std::env;
use std::ptr;
use uucore::error::USimpleError;
use uucore::show;

cpp! {{
#include <cstdio>
Expand Down Expand Up @@ -39,10 +37,13 @@ fn set_buffer(stream: *mut FILE, value: &str) {
"0" => (_IONBF, 0_usize),
"L" => (_IOLBF, 0_usize),
input => {
let buff_size: usize = input
.parse()
.map_err(|e| format!("incorrect size of buffer!: {}", e))
.unwrap();
let buff_size: usize = match input.parse() {
Ok(num) => num,
Err(_) => {
eprintln!("failed to allocate a {} byte stdio buffer", value);
std::process::exit(1);
}
};
(_IOFBF, buff_size as size_t)
}
};
Expand All @@ -53,7 +54,7 @@ fn set_buffer(stream: *mut FILE, value: &str) {
res = libc::setvbuf(stream, buffer, mode, size);
}
if res != 0 {
show!(USimpleError::new(res, "error while calling setvbuf!"));
eprintln!("could not set buffering of {:?} to mode {}", stream, mode);
}
}

Expand Down

0 comments on commit 1761a7d

Please sign in to comment.