retval(1)
This commit is contained in:
parent
8c55735e67
commit
b3cd51242c
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,9 +5,12 @@ bin/lowercase
|
||||
bin/nonzero
|
||||
bin/nutshell
|
||||
bin/pscat
|
||||
bin/retval
|
||||
bin/rldecode
|
||||
bin/rlencode
|
||||
bin/roll
|
||||
bin/roll_stdio
|
||||
bin/rot13
|
||||
bin/simexec
|
||||
bin/sleep
|
||||
bin/str
|
||||
|
11
Makefile
11
Makefile
@ -33,6 +33,7 @@ cleanprograms:
|
||||
$(RM) bin/str
|
||||
$(RM) bin/substitute
|
||||
$(RM) bin/sysexits
|
||||
$(RM) bin/retval
|
||||
$(RM) bin/rldecode
|
||||
$(RM) bin/rlencode
|
||||
$(RM) bin/roll
|
||||
@ -99,16 +100,22 @@ pscat.o: libio src/pscat.c
|
||||
pscat: libio 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
|
||||
$(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
|
||||
|
||||
roll_stdio.o: lib/libio.h src/roll.c sysexits
|
||||
$(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
|
||||
|
||||
rot13.o: libio sysexits src/rot13.c
|
||||
|
33
src/retval.c
33
src/retval.c
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user