Use expand_number(3) for less confusing argument processing

This commit is contained in:
Poul-Henning Kamp
2024-08-08 21:22:39 +00:00
parent 971c9f57d7
commit 06758ab134
2 changed files with 9 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
PROG= tcopy
LIBADD= util
.include <bsd.prog.mk>
+8 -2
View File
@@ -37,6 +37,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <libutil.h>
#include <paths.h>
#include <sys/sysctl.h>
#include <signal.h>
@@ -71,6 +72,7 @@ main(int argc, char *argv[])
const char *inf;
unsigned long maxphys = 0;
size_t l_maxphys = sizeof maxphys;
uint64_t tmp;
if (!sysctlbyname("kern.maxphys", &maxphys, &l_maxphys, NULL, 0))
maxblk = maxphys;
@@ -84,8 +86,12 @@ main(int argc, char *argv[])
op = COPYVERIFY;
break;
case 's':
maxblk = atoi(optarg);
if (maxblk <= 0) {
if (expand_number(optarg, &tmp)) {
warnx("illegal block size");
usage();
}
maxblk = tmp;
if (maxblk == 0) {
warnx("illegal block size");
usage();
}