From cf745918583fb8bead8ca9f5e335d4224e373d55 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Sun, 8 Jul 2012 10:12:00 +0000 Subject: Replace tricker atoi() and hand rolled parsing with strsep() and strtonum(). Make related error messages consistant. ok haesbaert@ --- sbin/fdisk/cmd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'sbin/fdisk') diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 8a9c447fc1b..56f1e0793ce 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.48 2012/07/07 16:00:19 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.49 2012/07/08 10:11:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -409,23 +409,25 @@ Xupdate(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) int Xflag(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) { + const char *errstr; int i, pn = -1, val = -1; - char *p; + char *part, *flag; - /* Parse partition table entry number */ - if (!isdigit(cmd->args[0])) { - printf("Invalid argument: %s [value]\n", - cmd->cmd); + flag = cmd->args; + part = strsep(&flag, " \t"); + + pn = (int)strtonum(part, 0, 3, &errstr); + if (errstr) { + printf("partition number is %s: %s.\n", errstr, part); return (CMD_CONT); } - pn = atoi(cmd->args); - p = strchr(cmd->args, ' '); - if (p != NULL) - val = strtol(p + 1, NULL, 0) & 0xff; - if (pn < 0 || pn > 3) { - printf("Invalid partition number.\n"); - return (CMD_CONT); + if (flag != NULL) { + val = (int)strtonum(flag, 0, 0xff, &errstr); + if (errstr) { + printf("flag value is %s: %s.\n", errstr, flag); + return (CMD_CONT); + } } if (val == -1) { -- cgit v1.2.3