Skip to content

Commit 9061b2b

Browse files
authored
libstdbuf: remove crash macro (uutils#5565)
* 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
1 parent 07241db commit 9061b2b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/stdbuf/src/libstdbuf/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ crate-type = [
2222
[dependencies]
2323
cpp = "0.5"
2424
libc = { workspace = true }
25-
uucore = { version = ">=0.0.19", package = "uucore", path = "../../../../uucore" }
2625

2726
[build-dependencies]
2827
cpp_build = "0.5"

src/uu/stdbuf/src/libstdbuf/src/libstdbuf.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
// spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf
66

77
use cpp::cpp;
8-
use libc::{c_char, c_int, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
8+
use libc::{c_char, c_int, fileno, size_t, FILE, _IOFBF, _IOLBF, _IONBF};
99
use std::env;
1010
use std::ptr;
11-
use uucore::crash;
1211

1312
cpp! {{
1413
#include <cstdio>
@@ -40,7 +39,10 @@ fn set_buffer(stream: *mut FILE, value: &str) {
4039
input => {
4140
let buff_size: usize = match input.parse() {
4241
Ok(num) => num,
43-
Err(e) => crash!(1, "incorrect size of buffer!: {}", e),
42+
Err(_) => {
43+
eprintln!("failed to allocate a {} byte stdio buffer", value);
44+
std::process::exit(1);
45+
}
4446
};
4547
(_IOFBF, buff_size as size_t)
4648
}
@@ -52,7 +54,11 @@ fn set_buffer(stream: *mut FILE, value: &str) {
5254
res = libc::setvbuf(stream, buffer, mode, size);
5355
}
5456
if res != 0 {
55-
crash!(res, "error while calling setvbuf!");
57+
eprintln!(
58+
"could not set buffering of {} to mode {}",
59+
unsafe { fileno(stream) },
60+
mode
61+
);
5662
}
5763
}
5864

0 commit comments

Comments
 (0)