Skip to content

Commit

Permalink
libstdbuf: remove crash macro (uutils#5565)
Browse files Browse the repository at this point in the history
* libstdbuf: remove crash macro

* libstdbuf: remove uucore macro/struct and use gnu messages

* libstdbuf: remove crash macro

* libstdbuf: remove uucore macro/struct and use gnu messages

* libstdbuf: remove :? from print by printing file descriptor instead of file

* merge main into libstdbuf-remove-crash-macro

* libstdbuf: remove uucore from dependencies
  • Loading branch information
cswn authored Nov 30, 2023
1 parent 07241db commit 9061b2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/uu/stdbuf/src/libstdbuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ crate-type = [
[dependencies]
cpp = "0.5"
libc = { workspace = true }
uucore = { version = ">=0.0.19", package = "uucore", path = "../../../../uucore" }

[build-dependencies]
cpp_build = "0.5"
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) },
mode
);
}
}

Expand Down

0 comments on commit 9061b2b

Please sign in to comment.