Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, rillig@NetBSD.org>
From: dieter roelants <dieter.NetBSD@pandora.be>
List: netbsd-bugs
Date: 12/02/2007 17:00:05
The following reply was made to PR bin/37414; it has been noted by GNATS.
From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 2 Dec 2007 17:55:40 +0100
... and here is the same patch inline, so people can read it after
being through gnats:
Index: fdisk.c
===================================================================
RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
retrieving revision 1.110
diff -u -r1.110 fdisk.c
--- fdisk.c 29 Nov 2007 23:19:25 -0000 1.110
+++ fdisk.c 2 Dec 2007 16:03:52 -0000
@@ -56,6 +56,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <vis.h>
@@ -2568,10 +2569,11 @@
decimal(const char *prompt, int dflt, int flags, int minval, int maxval)
{
int acc = 0;
+ int len, m;
char *cp;
- char ch;
for (;;) {
+ m = 1;
if (flags & DEC_SEC) {
printf("%s: [%d..%dcyl default: %d, %dcyl, %uMB] ",
prompt, SEC_TO_CYL(minval), SEC_TO_CYL(maxval),
@@ -2594,21 +2596,19 @@
if (isdigit((unsigned char)*cp) || *cp == '-') {
acc = strtol(lbuf, &cp, 10);
- if (flags & DEC_SEC) {
- ch = *cp;
- if (ch == 'g' || ch == 'G') {
+ len = strcspn(cp, " \t");
+ m = 0;
+ if (len && (flags & DEC_SEC)) {
+ if ((m = strncasecmp(cp, "GB", len)) == 0) {
acc *= 1024;
- ch = 'm';
}
- if (ch == 'm' || ch == 'M') {
+ if ((m *= strncasecmp(cp, "MB", len)) == 0) {
acc *= SEC_IN_1M;
/* round to whole number of cylinders */
acc += dos_cylindersectors / 2;
acc /= dos_cylindersectors;
- ch = 'c';
}
- if (ch == 'c' || ch == 'C') {
- cp++;
+ if ((m *= strncasecmp(cp, "cyl", len)) == 0) {
acc *= dos_cylindersectors;
/* adjustments for cylinder boundary */
if (acc == 0 && flags & DEC_RND_0)
@@ -2620,11 +2620,12 @@
if (flags & DEC_RND_DOWN_2)
acc -= dos_sectors;
}
+ cp += len;
}
}
cp += strspn(cp, " \t");
- if (*cp != '\0') {
+ if ((*cp != '\0') || (m != 0)) {
printf("%s is not a valid %s number.\n", lbuf,
flags & DEC_SEC ? "sector" : "decimal");
continue;
--
dieter