coreutils/util.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

/*
* This file is part of the uutils coreutils package.
*
* (c) Arcterus <arcterus@mail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#[macro_escape];
#[macro_export]
macro_rules! show_error(
($exitcode:expr, $($args:expr),+) => ({
::std::os::set_exit_status($exitcode);
safe_write!(&mut ::std::io::stderr(), "{}: error: ", NAME);
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
})
)
#[macro_export]
macro_rules! crash(
($exitcode:expr, $($args:expr),+) => ({
show_error!($exitcode, $($args),+);
unsafe { ::std::libc::exit($exitcode); }
})
)
#[macro_export]
macro_rules! safe_write(
($fd:expr, $($args:expr),+) => (
match write!($fd, $($args),+) {
Ok(_) => {}
Err(f) => { fail!(f.to_str()); }
}
)
)
#[macro_export]
macro_rules! safe_writeln(
($fd:expr, $($args:expr),+) => (
match writeln!($fd, $($args),+) {
Ok(_) => {}
Err(f) => { fail!(f.to_str()); }
}
)
)