1
0

retval(1)

This commit is contained in:
dtb 2022-08-23 12:49:42 -04:00
parent 8c55735e67
commit b3cd51242c
3 changed files with 29 additions and 18 deletions

3
.gitignore vendored
View File

@ -5,9 +5,12 @@ bin/lowercase
bin/nonzero bin/nonzero
bin/nutshell bin/nutshell
bin/pscat bin/pscat
bin/retval
bin/rldecode bin/rldecode
bin/rlencode bin/rlencode
bin/roll bin/roll
bin/roll_stdio
bin/rot13
bin/simexec bin/simexec
bin/sleep bin/sleep
bin/str bin/str

View File

@ -33,6 +33,7 @@ cleanprograms:
$(RM) bin/str $(RM) bin/str
$(RM) bin/substitute $(RM) bin/substitute
$(RM) bin/sysexits $(RM) bin/sysexits
$(RM) bin/retval
$(RM) bin/rldecode $(RM) bin/rldecode
$(RM) bin/rlencode $(RM) bin/rlencode
$(RM) bin/roll $(RM) bin/roll
@ -99,16 +100,22 @@ pscat.o: libio src/pscat.c
pscat: libio pscat.o pscat: libio pscat.o
$(CC) $(CFLAGS) -o bin/pscat build/libio.o build/pscat.o $(CC) $(CFLAGS) -o bin/pscat build/libio.o build/pscat.o
retval.o: libio src/retval.c sysexits
$(CC) $(CFLAGS) -c -o build/retval.o src/retval.c
retval: libio retval.o
$(CC) $(CFLAGS) -o bin/retval build/retval.o build/libio.o
roll.o: lib/libio.h src/roll.c sysexits roll.o: lib/libio.h src/roll.c sysexits
$(CC) $(CFLAGS) -c -o build/roll.o src/roll.c $(CC) $(CFLAGS) -c -o build/roll.o src/roll.c
roll: libio sysexits roll.o roll: libio roll.o
$(CC) $(CFLAGS) -o bin/roll build/libio.o build/roll.o $(CC) $(CFLAGS) -o bin/roll build/libio.o build/roll.o
roll_stdio.o: lib/libio.h src/roll.c sysexits roll_stdio.o: lib/libio.h src/roll.c sysexits
$(CC) $(CFLAGS) -c -DUSE_STDIO -o build/roll_stdio.o src/roll.c $(CC) $(CFLAGS) -c -DUSE_STDIO -o build/roll_stdio.o src/roll.c
roll_stdio: libio sysexits roll_stdio.o roll_stdio: libio roll_stdio.o
$(CC) $(CFLAGS) -o bin/roll_stdio build/libio.o build/roll_stdio.o $(CC) $(CFLAGS) -o bin/roll_stdio build/libio.o build/roll_stdio.o
rot13.o: libio sysexits src/rot13.c rot13.o: libio sysexits src/rot13.c

View File

@ -1,24 +1,25 @@
#include <ascii.h> #include <ctype.h> /* isdigit(3) */
#include <stdio.h> #include <sysexits.h> /* EX_USAGE */
#include <stdlib.h> #include <unistd.h> /* write(2) */
#include <sysexits.h> #include "libio.h" /* fdprint(3), parse_uint(3) */
#include "libstr.h"
#include "noargvzero.h" static char *program_name = "retval";
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
int retval; unsigned int s;
NOARGVZERO(argv); if(argc < 2){
usage: write(2, "Usage: ", 7);
if(argv[1] == NULL){ fdprint(2, argv[0] == NULL ? program_name : argv[0]);
fprintf(stderr, "Usage: %s [exit code]\n", argv[0]); write(2, " [status]\n", 10);
return EX_USAGE; return EX_USAGE;
} }
if(strint(argv[1], &retval, ASCII_DIGITS_DECIMAL_UPPER) == NULL){ for(s = 0; argv[1][s] != '\0'; ++s)
fprintf(stderr, "%s: %s: Not an integer\n", argv[0], argv[1]); if(!isdigit(argv[1][s]))
return EX_USAGE; goto usage;
}
return retval; s = parse_uint(argv[1]);
return s;
} }