cgpt: unify cli int parsing error checking

Most of the cmd funcs had the same logic copied & pasted multiple times
over.  Unify them into a common header.

BUG=chromium:644845
TEST=precq passes
TEST=passing invalid args to some funcs is caught
BRANCH=None

Change-Id: Ib7212bcbb17da1135b2508a52910aac37ee8e6cd
Reviewed-on: https://chromium-review.googlesource.com/382691
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Mike Frysinger
2016-09-07 20:23:46 -04:00
committed by chrome-bot
parent 61c4ee12be
commit c60eb7e735
10 changed files with 43 additions and 121 deletions

View File

@@ -39,22 +39,14 @@ int cmd_create(int argc, char *argv[]) {
{
case 'D':
params.drive_size = strtoull(optarg, &e, 0);
if (!*optarg || (e && *e))
{
Error("invalid argument to -%c: \"%s\"\n", c, optarg);
errorcnt++;
}
errorcnt += check_int_parse(c, e);
break;
case 'z':
params.zap = 1;
break;
case 'p':
params.padding = strtoull(optarg, &e, 0);
if (!*optarg || (e && *e))
{
Error("invalid argument to -%c: \"%s\"\n", c, optarg);
errorcnt++;
}
errorcnt += check_int_parse(c, e);
break;
case 'h':
Usage();