mirror of
https://github.com/uutils/coreutils
synced 2024-12-16 08:12:39 +00:00
962a6bbf2f
Replace `show_error!` with Result<(), int> and `display_error!`
95 lines
2.2 KiB
Rust
95 lines
2.2 KiB
Rust
/*
|
|
* 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]
|
|
|
|
extern crate libc;
|
|
|
|
#[macro_export]
|
|
macro_rules! show_error(
|
|
($exitcode:expr, $($args:expr),+) => ({
|
|
::std::os::set_exit_status($exitcode as int);
|
|
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
|
})
|
|
)
|
|
|
|
// FIXME #211: Transitional until there are no further users of `show_error!`.
|
|
// Then this can be renamed.
|
|
#[macro_export]
|
|
macro_rules! display_error(
|
|
($($args:expr),+) => ({
|
|
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
|
})
|
|
)
|
|
|
|
#[macro_export]
|
|
macro_rules! show_warning(
|
|
($($args:expr),+) => ({
|
|
safe_write!(&mut ::std::io::stderr(), "{}: warning: ", ::NAME);
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
|
})
|
|
)
|
|
|
|
#[macro_export]
|
|
macro_rules! crash(
|
|
($exitcode:expr, $($args:expr),+) => ({
|
|
show_error!($exitcode, $($args),+);
|
|
unsafe { self::libc::exit($exitcode as self::libc::c_int); }
|
|
})
|
|
)
|
|
|
|
|
|
#[macro_export]
|
|
macro_rules! exit(
|
|
($exitcode:expr) => ({
|
|
unsafe { self::libc::exit($exitcode); }
|
|
})
|
|
)
|
|
|
|
#[macro_export]
|
|
macro_rules! crash_if_err(
|
|
($exitcode:expr, $exp:expr) => (
|
|
match $exp {
|
|
Ok(m) => m,
|
|
Err(f) => crash!($exitcode, "{}", f.to_str())
|
|
}
|
|
)
|
|
)
|
|
|
|
#[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()); }
|
|
}
|
|
)
|
|
)
|
|
|
|
#[macro_export]
|
|
macro_rules! safe_unwrap(
|
|
($exp:expr) => (
|
|
match $exp {
|
|
Ok(m) => m,
|
|
Err(f) => crash!(1, "{}", f.to_str())
|
|
}
|
|
)
|
|
)
|