summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2011-03-01 22:03:54 -0500
committersrs5694 <srs5694@users.sourceforge.net>2011-03-01 22:03:54 -0500
commit64cbd171067eb34054741bfcd73f0b91d727a371 (patch)
treeb5964f8b2476429a45a683937d434c2278ca63b2 /support.cc
parentf2efa7defc5db19ede49ac4a7dc298eaf47c8ac0 (diff)
downloadsgdisk-64cbd171067eb34054741bfcd73f0b91d727a371.tar.gz
Misc. bug fixes & restructuring.
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc27
1 files changed, 10 insertions, 17 deletions
diff --git a/support.cc b/support.cc
index ee44566..bd0b28b 100644
--- a/support.cc
+++ b/support.cc
@@ -63,11 +63,13 @@ int GetNumber(int low, int high, int def, const string & prompt) {
char GetYN(void) {
char line[255];
char response;
- char *junk;
do {
cout << "(Y/N): ";
- junk = fgets(line, 255, stdin);
+ if (!fgets(line, 255, stdin)) {
+ cerr << "Critical error! Failed fgets() in GetYN()\n";
+ exit(1);
+ } // if
sscanf(line, "%c", &response);
if (response == 'y')
response = 'Y';
@@ -306,32 +308,23 @@ void ReverseBytes(void* theValue, int numBytes) {
// Extract integer data from argument string, which should be colon-delimited
uint64_t GetInt(const string & argument, int itemNum) {
- int startPos = -1, endPos = -1;
- uint64_t retval = 0;
+ uint64_t retval;
- while (itemNum-- > 0) {
- startPos = endPos + 1;
- endPos = (int) argument.find(':', startPos);
- }
- if (endPos == (int) string::npos)
- endPos = (int) argument.length();
- endPos--;
-
- istringstream inString(argument.substr(startPos, endPos - startPos + 1));
+ istringstream inString(GetString(argument, itemNum));
inString >> retval;
return retval;
} // GetInt()
// Extract string data from argument string, which should be colon-delimited
string GetString(const string & argument, int itemNum) {
- int startPos = -1, endPos = -1;
+ size_t startPos = -1, endPos = -1;
while (itemNum-- > 0) {
startPos = endPos + 1;
- endPos = (int) argument.find(':', startPos);
+ endPos = argument.find(':', startPos);
}
- if (endPos == (int) string::npos)
- endPos = (int) argument.length();
+ if (endPos == string::npos)
+ endPos = argument.length();
endPos--;
return argument.substr(startPos, endPos - startPos + 1);