2015-12-24 06:11:00 +00:00
|
|
|
//! stdio convenience fns
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
|
|
|
|
use std::io::{stderr, stdout, Write};
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
pub static EXIT_OK: i32 = 0;
|
|
|
|
pub static EXIT_ERR: i32 = 1;
|
|
|
|
|
2016-02-15 05:47:02 +00:00
|
|
|
pub fn err_msg(msg: &str) {
|
2015-12-24 06:11:00 +00:00
|
|
|
let exe_path = match env::current_exe() {
|
|
|
|
Ok(p) => p.to_string_lossy().into_owned(),
|
2016-02-15 05:47:02 +00:00
|
|
|
_ => String::from(""),
|
2015-12-24 06:11:00 +00:00
|
|
|
};
|
2016-02-15 05:47:02 +00:00
|
|
|
writeln!(&mut stderr(), "{}: {}", exe_path, msg).unwrap();
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// by default stdout only flushes
|
|
|
|
// to console when a newline is passed.
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_char(c: &char) {
|
|
|
|
print!("{}", c);
|
|
|
|
stdout().flush();
|
|
|
|
}
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_str(s: &str) {
|
|
|
|
print!("{}", s);
|
|
|
|
stdout().flush();
|
|
|
|
}
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
pub fn flush_bytes(bslice: &[u8]) {
|
|
|
|
stdout().write(bslice);
|
|
|
|
stdout().flush();
|
|
|
|
}
|