From e9a0632db4c5c099d14de47ee78e069a157a620b Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Mon, 1 Dec 2008 20:15:36 +0000 Subject: Back out previous; it broke specifying paritions sizes with decimals, e.g. "0.5g". --- sbin/fdisk/misc.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'sbin/fdisk') diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index 7656e8d1a73..ad20c5dafee 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.19 2008/12/01 04:05:43 ray Exp $ */ +/* $OpenBSD: misc.c,v 1.20 2008/12/01 20:15:35 ray Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -30,7 +30,9 @@ #include #include #include +#include #include +#include #include "misc.h" struct unit_type unit_types[] = { @@ -193,17 +195,16 @@ putlong(void *p, u_int32_t l) /* * adapted from sbin/disklabel/editor.c - * retries on error + * Returns UINT_MAX on error */ u_int32_t getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval, u_int32_t maxval, u_int32_t offset, int flags) { - char buf[BUFSIZ], *p, operator; - const char *errstr; + char buf[BUFSIZ], *endptr, *p, operator = '\0'; u_int32_t rval = oval; size_t n; - int mult, secsize = unit_types[SECTORS].conversion; + int mult = 1, secsize = unit_types[SECTORS].conversion; double d; int secpercyl; @@ -212,9 +213,7 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval, /* We only care about the remainder */ offset = offset % secpercyl; - restart: - mult = 1; - operator = '\0'; + buf[0] = '\0'; do { printf("%s: [%u] ", prompt, oval); if (fgets(buf, sizeof(buf), stdin) == NULL) { @@ -222,6 +221,7 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval, if (feof(stdin)) { clearerr(stdin); putchar('\n'); + return(UINT_MAX - 1); } } n = strlen(buf); @@ -273,10 +273,15 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval, if (*p == '+' || *p == '-') operator = *p++; - d = strtonum(p, 0, maxval, &errstr); - if (errstr) - goto restart; - else { + endptr = p; + errno = 0; + d = strtod(p, &endptr); + if (errno == ERANGE) + rval = UINT_MAX; /* too big/small */ + else if (*endptr != '\0') { + errno = EINVAL; /* non-numbers in str */ + rval = UINT_MAX; + } else { /* XXX - should check for overflow */ if (mult > 0) rval = d * mult; @@ -292,7 +297,7 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval, } } } - if (flags & DO_ROUNDING) { + if ((flags & DO_ROUNDING) && rval < UINT_MAX) { #ifndef CYLCHECK /* Round to nearest cylinder unless given in sectors */ if (mult != 1) -- cgit v1.2.3