summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-02-19 17:19:55 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-02-19 17:19:55 -0500
commit08bb0da07953af605b4918e268272de15ac151aa (patch)
tree401ff14b62ddfda4c4c64b3dfcee817ad8133971 /support.cc
parentfad064250bf6c49eb4966bf0f617591a0821808e (diff)
downloadsgdisk-08bb0da07953af605b4918e268272de15ac151aa.tar.gz
Version 0.6.4
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/support.cc b/support.cc
index f179c2f..168262e 100644
--- a/support.cc
+++ b/support.cc
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <string>
#include <iostream>
+#include <sstream>
#include "support.h"
#include <sys/types.h>
@@ -166,10 +167,9 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string &
// form
string BytesToSI(uint64_t size) {
string units;
- char theValue[99];
+ ostringstream theValue;
float sizeInSI;
- theValue[0] = '\0';
sizeInSI = (float) size;
units = " bytes";
if (sizeInSI > 1024.0) {
@@ -192,12 +192,14 @@ string BytesToSI(uint64_t size) {
sizeInSI /= 1024.0;
units = " PiB";
} // if
+ theValue.setf(ios::fixed);
if (units == " bytes") { // in bytes, so no decimal point
- sprintf(theValue, "%1.0f%s", sizeInSI, units.c_str());
+ theValue.precision(0);
} else {
- sprintf(theValue, "%1.1f%s", sizeInSI, units.c_str());
+ theValue.precision(1);
} // if/else
- return theValue;
+ theValue << sizeInSI << units;
+ return theValue.str();
} // BlocksToSI()
// Converts two consecutive characters in the input string into a