diff options
-rw-r--r-- | holes.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/holes.c b/holes.c index 865ea50..c618a8e 100644 --- a/holes.c +++ b/holes.c @@ -49,13 +49,27 @@ int main(int argc, char *argv[]) { int c, i; + char *e; argv0 = argv[0]; while ((c = getopt(argc, argv, "n:")) != -1) switch(c) { case 'n': - minlen = atoll(optarg); + errno = 0; + minlen = strtoll(optarg, &e, 0); + if (errno != 0 || *e) { + fprintf(stderr, + "%s: can't parse length '%s'.\n", + argv0, optarg); + exit(2); + } + if (minlen < 1) { + fprintf(stderr, + "%s: MINLEN must not be smaller than 1.\n", + argv0); + exit(2); + } break; default: fprintf(stderr, @@ -63,12 +77,6 @@ main(int argc, char *argv[]) exit(2); } - if (minlen < 1) { - fprintf(stderr, "%s: MINLEN must not be smaller than 1.\n", - argv0); - exit(2); - } - if (optind == argc) holes(stdin, 0); else |