Compare commits
No commits in common. "bdd388e6d434c051d9217c437ef1ce6d15ac17e2" and "e9da63243fd603221f873b5ec41bb268fd275edf" have entirely different histories.
bdd388e6d4
...
e9da63243f
@ -1,24 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
}
|
|
24
retval/retval.c
Normal file
24
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 */
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
@ -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 */)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user