diff options
author | Gleydson Soares <gsoares@cvs.openbsd.org> | 2016-01-27 13:42:09 +0000 |
---|---|---|
committer | Gleydson Soares <gsoares@cvs.openbsd.org> | 2016-01-27 13:42:09 +0000 |
commit | 4bfaaf42ae643e13a5ef2037af83095bac63555d (patch) | |
tree | 2539028831bb3e7984af0db878295f7118932564 /games | |
parent | 265ddf865d2981d12cca3e11d25d7d171f652233 (diff) |
- optarg and optind are declared by unistd.h, so remove them...
- use strtonum rather than atoi
- zap case '?' in getopt(3) switch
- use _exit(2) in signal handler
- use __progname in usage() instead of hardcoded name
OK tb@ mestre@
Diffstat (limited to 'games')
-rw-r--r-- | games/arithmetic/arithmetic.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/games/arithmetic/arithmetic.c b/games/arithmetic/arithmetic.c index 8459a8b60d0..bef0cf7feb0 100644 --- a/games/arithmetic/arithmetic.c +++ b/games/arithmetic/arithmetic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arithmetic.c,v 1.25 2016/01/25 21:17:45 mestre Exp $ */ +/* $OpenBSD: arithmetic.c,v 1.26 2016/01/27 13:42:08 gsoares Exp $ */ /* * Copyright (c) 1989, 1993 @@ -62,6 +62,7 @@ #include <err.h> #include <ctype.h> +#include <limits.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -95,9 +96,8 @@ time_t qtime; int main(int argc, char *argv[]) { - extern char *optarg; - extern int optind; int ch, cnt; + const char *errstr; if (pledge("stdio", NULL) == -1) err(1, "pledge"); @@ -114,10 +114,10 @@ main(int argc, char *argv[]) break; } case 'r': - if ((rangemax = atoi(optarg)) <= 0) - errx(1, "invalid range."); + rangemax = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr) + errx(1, "invalid range, %s: %s", errstr, optarg); break; - case '?': case 'h': default: usage(); @@ -141,7 +141,7 @@ void intr(int dummy) { showstats(); - exit(0); + _exit(0); } /* Print score. Original `arithmetic' had a delay after printing it. */ @@ -355,6 +355,7 @@ opnum(int op) void usage(void) { - (void)fprintf(stderr, "usage: arithmetic [-o +-x/] [-r range]\n"); + extern char *__progname; + (void)fprintf(stderr, "usage: %s [-o +-x/] [-r range]\n", __progname); exit(1); } |