retval(1)
This commit is contained in:
+17
-16
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user