mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 01:00:31 +00:00
Move exit code function to separate file
This commit is contained in:
1 parent
811e6b5fcd
commit
b658e20110
3 files changed
+24
-21
No files matched your search
@@ -0,0 +1,22 @@
|
||||
use std::process::ExitStatus;
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
||||
// From the ExitStatus::code documentation:
|
||||
//
|
||||
// "On Unix, this will return None if the process was terminated by a signal."
|
||||
//
|
||||
// In that case, ExitStatusExt::signal should never return None.
|
||||
//
|
||||
// To differentiate between "normal" exit codes and signals, we are using a technique
|
||||
// similar to bash (https://tldp.org/LDP/abs/html/exitcodes.html) and add 128 to the
|
||||
// signal value.
|
||||
status.code().or_else(|| status.signal().map(|s| s + 128))
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
pub fn extract_exit_code(status: ExitStatus) -> Option<i32> {
|
||||
status.code()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod exit_code;
|
||||
pub mod min_max;
|
||||
pub mod number;
|
||||
pub mod units;
|
||||
Reference in new issue
Block a user