Use utility functions

This commit is contained in:
Lucas 2020-03-08 21:24:10 +00:00
parent b13f35e0e6
commit dbd7618c9f
7 changed files with 48 additions and 201 deletions

View file

@ -15,8 +15,6 @@
#define _DEFAULT_SOURCE
#endif
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@ -41,7 +39,6 @@ int
main(int argc, char *argv[])
{
char *end;
intmax_t v;
long seed;
int ch;
@ -49,15 +46,7 @@ main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "s:")) != -1)
switch (ch) {
case 's':
errno = 0;
v = strtoimax(optarg, &end, 0);
if (*end != '\0' || errno != 0 || v > LONG_MAX ||
v < LONG_MIN) {
fprintf(stderr, "-s: Invalid value \"%s\".",
optarg);
exit(1);
}
seed = (long)v;
seed = parse_integer(optarg, LONG_MIN, LONG_MAX);
break;
default:
usage();