1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

libstdbuf: remove crash macro (#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
This commit is contained in:
clara swanson 2023-11-30 11:01:31 +01:00 committed by GitHub
parent 07241db6d8
commit 9061b2ba7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

1
Cargo.lock generated
View file

@ -2952,7 +2952,6 @@ dependencies = [
"cpp", "cpp",
"cpp_build", "cpp_build",
"libc", "libc",
"uucore",
] ]
[[package]] [[package]]

View file

@ -22,7 +22,6 @@ crate-type = [
[dependencies] [dependencies]
cpp = "0.5" cpp = "0.5"
libc = { workspace = true } libc = { workspace = true }
uucore = { version = ">=0.0.19", package = "uucore", path = "../../../../uucore" }
[build-dependencies] [build-dependencies]
cpp_build = "0.5" cpp_build = "0.5"

View file

@ -5,10 +5,9 @@
// spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf // spell-checker:ignore (ToDO) IOFBF IOLBF IONBF cstdio setvbuf
use cpp::cpp; 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::env;
use std::ptr; use std::ptr;
use uucore::crash;
cpp! {{ cpp! {{
#include <cstdio> #include <cstdio>
@ -40,7 +39,10 @@ fn set_buffer(stream: *mut FILE, value: &str) {
input => { input => {
let buff_size: usize = match input.parse() { let buff_size: usize = match input.parse() {
Ok(num) => num, 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) (_IOFBF, buff_size as size_t)
} }
@ -52,7 +54,11 @@ fn set_buffer(stream: *mut FILE, value: &str) {
res = libc::setvbuf(stream, buffer, mode, size); res = libc::setvbuf(stream, buffer, mode, size);
} }
if res != 0 { if res != 0 {
crash!(res, "error while calling setvbuf!"); eprintln!(
"could not set buffering of {} to mode {}",
unsafe { fileno(stream) },
mode
);
} }
} }