mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
Ensure any pending stdout writes are flushed.
Since stdout is line-buffered by default, we need to ensure any pending writes are flushed before exiting. Ideally, this should be enforced by each utility. Since all utilities are wrapped by mkmain, this was a convenient location to enforce this behavior. I previously was handling this on a case-by-case basis. See: https://github.com/rust-lang/rust/issues/23818
This commit is contained in:
parent
505060107c
commit
174b834e67
1 changed files with 12 additions and 2 deletions
14
mkmain.rs
14
mkmain.rs
|
@ -5,11 +5,21 @@ use std::fs::File;
|
||||||
static TEMPLATE: &'static str = "\
|
static TEMPLATE: &'static str = "\
|
||||||
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
|
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
|
||||||
|
|
||||||
use std::env;
|
use std::io::Write;
|
||||||
use uu@UTIL_CRATE@::uumain;
|
use uu@UTIL_CRATE@::uumain;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
std::process::exit(uumain(env::args().collect()));
|
let code = uumain(std::env::args().collect());
|
||||||
|
|
||||||
|
// Since stdout is line-buffered by default, we need to ensure any pending
|
||||||
|
// writes are flushed before exiting. Ideally, this should be enforced by
|
||||||
|
// each utility.
|
||||||
|
//
|
||||||
|
// See: https://github.com/rust-lang/rust/issues/23818
|
||||||
|
//
|
||||||
|
std::io::stdout().flush().unwrap();
|
||||||
|
|
||||||
|
std::process::exit(code);
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue