1
Fork 0
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:
Joseph Crail 2015-05-30 19:02:33 -04:00
parent 505060107c
commit 174b834e67

View file

@ -5,11 +5,21 @@ use std::fs::File;
static TEMPLATE: &'static str = "\
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
use std::env;
use std::io::Write;
use uu@UTIL_CRATE@::uumain;
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);
}
";