1
0

retval(1): Rewrite in Rust

This commit is contained in:
dtb 2024-04-18 22:36:24 -06:00
parent d0527ea349
commit b1f90eff11
5 changed files with 22 additions and 2 deletions

View File

@ -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
View 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]),
}
}