summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
commit55d926192adc984462509b2966e23bc0d1129bbd (patch)
treebff8bea805e3fb0e15f7f3a0cd26a20fa12c5f29 /support.cc
parentea17cffd083c839b7af3560d55ba697667277901 (diff)
downloadsgdisk-55d926192adc984462509b2966e23bc0d1129bbd.tar.gz
Updated project files for 0.6.5 release version.
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc27
1 files changed, 13 insertions, 14 deletions
diff --git a/support.cc b/support.cc
index 168262e..ab8f767 100644
--- a/support.cc
+++ b/support.cc
@@ -84,11 +84,9 @@ char GetYN(void) {
// specified number of sectors (or KiB, MiB, etc.). Use the def
//value as the default if the user just hits Enter
uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string & prompt) {
- unsigned long long response;
- int num, plusFlag = 0;
- uint64_t mult = 1;
- char suffix;
- char line[255];
+ uint64_t response, mult = 1;
+ int plusFlag = 0;
+ char suffix, line[255];
response = low - 1; // Ensure one pass by setting a too-low initial value
while ((response < low) || (response > high)) {
@@ -112,12 +110,13 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string &
} // if
// Extract numeric response and, if present, suffix
- num = sscanf(line, "%llu%c", &response, &suffix);
+ istringstream inString(line);
+ inString >> response >> suffix;
// If no response, use default (def)
- if (num <= 0) {
- response = (unsigned long long) def;
- suffix = ' ';
+ if (strlen(line) == 0) {
+ response = def;
+ suffix = ' ';
plusFlag = 0;
} // if
@@ -144,22 +143,22 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string &
} // switch
// Adjust response based on multiplier and plus flag, if present
- response *= (unsigned long long) mult;
+ response *= mult;
if (plusFlag == 1) {
// Recompute response based on low part of range (if default = high
// value, which should be the case when prompting for the end of a
// range) or the defaut value (if default != high, which should be
// the case for the first sector of a partition).
if (def == high)
- response = response + (unsigned long long) low - UINT64_C(1);
+ response = response + low - UINT64_C(1);
else
- response = response + (unsigned long long) def - UINT64_C(1);
+ response = response + def - UINT64_C(1);
} // if
if (plusFlag == -1) {
- response = (unsigned long long) high - response;
+ response = high - response;
} // if
} // while
- return ((uint64_t) response);
+ return response;
} // GetSectorNum()
// Takes a size in bytes (in size) and converts this to a size in