summaryrefslogtreecommitdiff
path: root/sgdisk.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2011-03-15 00:34:10 -0400
committersrs5694 <srs5694@users.sourceforge.net>2011-03-15 00:34:10 -0400
commit9a46b042c57144c26a67781d335e6ba4128382d2 (patch)
treea7126d54e9cd8387251787c7f1da6cfb7b44b8f2 /sgdisk.cc
parentd3ba7a61f68ca97fc3828f0c2edd7cda7ca3dfda (diff)
downloadsgdisk-9a46b042c57144c26a67781d335e6ba4128382d2.tar.gz
Patches supplied by Florian Zumbiehl
Diffstat (limited to 'sgdisk.cc')
-rw-r--r--sgdisk.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/sgdisk.cc b/sgdisk.cc
index 11df6ed..1f3e792 100644
--- a/sgdisk.cc
+++ b/sgdisk.cc
@@ -13,6 +13,7 @@
#include <popt.h>
#include <errno.h>
#include <stdint.h>
+#include <string.h>
#include <string>
#include <iostream>
#include <sstream>
@@ -438,6 +439,7 @@ int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) {
if ((&theGPT != NULL) && (argument != NULL)) {
numParts = CountColons(argument) + 1;
+ cout << "numParts = " << numParts << "\n";
if (numParts <= (4 - isHybrid)) {
newMBR.SetDisk(theGPT.GetDisk());
for (i = 0; i < numParts; i++) {
@@ -464,15 +466,14 @@ int BuildMBR(GPTData & theGPT, char* argument, int isHybrid) {
return allOK;
} // BuildMBR()
-// Returns the number of colons in argument string
+// Returns the number of colons in argument string, ignoring the
+// first character (thus, a leading colon is ignored, as GetString()
+// does).
int CountColons(char* argument) {
- int num = 0, i = 0;
+ int num = 0;
+
+ while ((argument[0] != '\0') && (argument = strchr(&argument[1], ':')))
+ num++;
- if (argument != NULL) {
- while (argument[i] != '\0') {
- if (argument[i++] == ':')
- num++;
- } // while
- } // if
return num;
} // CountColons()