Compare commits
5 Commits
e9da63243f
...
bdd388e6d4
Author | SHA1 | Date | |
---|---|---|---|
bdd388e6d4 | |||
c10ffcabf1 | |||
de267d32d4 | |||
4a405fdfbb | |||
df1b0a2d9d |
24
Retired/retval/retval.c
Normal file
24
Retired/retval/retval.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <errno.h> /* errno */
|
||||||
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
|
#include <stdlib.h> /* strtol(3) */
|
||||||
|
#include <sysexits.h> /* EX_USAGE */
|
||||||
|
|
||||||
|
char *program_name = "retval";
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
|
||||||
|
switch(argc){
|
||||||
|
case 2: {
|
||||||
|
unsigned int s;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
s = strtol(argv[1], &argv[1], 10);
|
||||||
|
|
||||||
|
if(*argv[1] == '\0' && errno == 0) { return s; }
|
||||||
|
} /* FALLTHROUGH */
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Usage: %s status\n",
|
||||||
|
argv[0] == NULL ? program_name : argv[0]);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
use std::{env::args, process::ExitCode};
|
use std::{env::args, process::ExitCode};
|
||||||
|
|
||||||
fn usage(s: &str) -> ExitCode {
|
fn usage(s: &str) -> ExitCode {
|
||||||
eprintln!("Usage: {} [status]", s);
|
eprintln!("Usage: {} status", s);
|
||||||
ExitCode::from(64 /* NetBSD sysexits(3) EX_USAGE */)
|
ExitCode::from(64 /* NetBSD sysexits(3) EX_USAGE */)
|
||||||
}
|
}
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <errno.h> /* errno */
|
|
||||||
#include <stdio.h> /* fprintf(3), stderr */
|
|
||||||
#include <stdlib.h> /* strtol(3) */
|
|
||||||
#include <sysexits.h> /* EX_USAGE */
|
|
||||||
|
|
||||||
int usage(char *s){
|
|
||||||
fprintf(stderr, "Usage: %s [status]\n", s == NULL ? "retval" : s);
|
|
||||||
return EX_USAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
|
||||||
|
|
||||||
switch(argc){
|
|
||||||
case 2: { unsigned int s;
|
|
||||||
errno = 0;
|
|
||||||
s = strtol(argv[1], &argv[1], 10);
|
|
||||||
if(*argv[1] != '\0' || errno != 0){
|
|
||||||
return usage(argv[0]);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
default: return usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user