Move exit code function to separate file

This commit is contained in:
David Peter authored and David Peter committed 2022-02-22 09:07:40 +01:00
1 parent 811e6b5fcd
commit b658e20110
3 files changed
+24 -21

No files matched your search

+22
View File
@@ -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
View File
@@ -1,3 +1,4 @@
pub mod exit_code;
pub mod min_max;
pub mod number;
pub mod units;