1
0

Compare commits

..

No commits in common. "bdd388e6d434c051d9217c437ef1ce6d15ac17e2" and "e9da63243fd603221f873b5ec41bb268fd275edf" have entirely different histories.

9 changed files with 25 additions and 25 deletions

View File

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

View File

@ -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 */)
} }