retval(1)

This commit is contained in:
2022-08-23 12:49:42 -04:00
parent 8c55735e67
commit b3cd51242c
3 changed files with 29 additions and 18 deletions
+17 -16
View File
@@ -1,24 +1,25 @@
#include <ascii.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include "libstr.h"
#include "noargvzero.h"
#include <ctype.h> /* isdigit(3) */
#include <sysexits.h> /* EX_USAGE */
#include <unistd.h> /* write(2) */
#include "libio.h" /* fdprint(3), parse_uint(3) */
static char *program_name = "retval";
int main(int argc, char *argv[]){
int retval;
unsigned int s;
NOARGVZERO(argv);
if(argv[1] == NULL){
fprintf(stderr, "Usage: %s [exit code]\n", argv[0]);
if(argc < 2){
usage: write(2, "Usage: ", 7);
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
write(2, " [status]\n", 10);
return EX_USAGE;
}
if(strint(argv[1], &retval, ASCII_DIGITS_DECIMAL_UPPER) == NULL){
fprintf(stderr, "%s: %s: Not an integer\n", argv[0], argv[1]);
return EX_USAGE;
}
for(s = 0; argv[1][s] != '\0'; ++s)
if(!isdigit(argv[1][s]))
goto usage;
return retval;
s = parse_uint(argv[1]);
return s;
}