retval(1): make C and Rust code similar
This commit is contained in:
parent
b1f90eff11
commit
f3893c4da1
@ -3,21 +3,22 @@
|
|||||||
#include <stdlib.h> /* strtol(3) */
|
#include <stdlib.h> /* strtol(3) */
|
||||||
#include <sysexits.h> /* EX_USAGE */
|
#include <sysexits.h> /* EX_USAGE */
|
||||||
|
|
||||||
static char *program_name = "retval";
|
int usage(char *s){
|
||||||
|
fprintf(stderr, "Usage: %s [status]\n", s == NULL ? "retval" : s);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
unsigned int s;
|
|
||||||
|
|
||||||
if(argc < 2)
|
switch(argc){
|
||||||
goto usage;
|
case 2: { unsigned int s;
|
||||||
|
errno = 0;
|
||||||
errno = 0;
|
s = strtol(argv[1], &argv[1], 10);
|
||||||
s = strtol(argv[1], &argv[1], 10);
|
if(*argv[1] != '\0' || errno != 0){
|
||||||
if(*argv[1] != '\0' || errno != 0){
|
return usage(argv[0]);
|
||||||
usage: fprintf(stderr, "Usage: %s [status]\n",
|
}
|
||||||
argv[0] == NULL ? program_name : argv[0]);
|
return s;
|
||||||
return EX_USAGE;
|
}
|
||||||
|
default: return usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user