retval(1): Rewrite in Rust
This commit is contained in:
parent
d0527ea349
commit
b1f90eff11
@ -1,2 +1,4 @@
|
|||||||
retval: retval.c
|
RUSTC = rustc
|
||||||
$(CC) -o retval retval.c
|
|
||||||
|
retval: retval.rs
|
||||||
|
$(RUSTC) $(RUSTCFLAGS) -o retval retval.rs
|
||||||
|
18
retval/retval.rs
Normal file
18
retval/retval.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use std::{env::args, process::ExitCode};
|
||||||
|
|
||||||
|
fn usage(s: &str) -> ExitCode {
|
||||||
|
eprintln!("Usage: {} [status]", s);
|
||||||
|
ExitCode::from(64 /* NetBSD sysexits(3) EX_USAGE */)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> ExitCode {
|
||||||
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
|
match argv.len() {
|
||||||
|
2 => match argv[1].parse::<u8>() {
|
||||||
|
Ok(e) => ExitCode::from(e),
|
||||||
|
_ => usage(&argv[0]),
|
||||||
|
},
|
||||||
|
_ => usage(&argv[0]),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user