aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2011-03-15 17:38:02 +0100
committerDavid 'Digit' Turner <digit@android.com>2011-03-15 17:39:21 +0100
commite85871f98fe50edd8135e5ce8aff04c3ad518d1a (patch)
tree6ba2d247374b4bfa819bc9110dfa754199e84f2c /android/utils
parent356e18be0ec6c7d92d116f75130e2cb8db4b114a (diff)
downloadexternal_qemu-e85871f98fe50edd8135e5ce8aff04c3ad518d1a.zip
external_qemu-e85871f98fe50edd8135e5ce8aff04c3ad518d1a.tar.gz
external_qemu-e85871f98fe50edd8135e5ce8aff04c3ad518d1a.tar.bz2
Fix write of disk sizes in ini files.
The old implementation always expressed the size as multiples of kilobytes due to an improper order to size checks. For example, 66MB was written as '67584k' instead of '66m', which is correct but sub-optimal. Change-Id: I6365bf4c269ed7d213043182a8ae501713798b8f
Diffstat (limited to 'android/utils')
-rw-r--r--android/utils/ini.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/android/utils/ini.c b/android/utils/ini.c
index a5914dd..ff4a8af 100644
--- a/android/utils/ini.c
+++ b/android/utils/ini.c
@@ -480,19 +480,22 @@ iniFile_setDiskSize( IniFile* f, const char* key, int64_t size )
{
char temp[32];
int64_t divisor = 0;
+ const int64_t kilo = 1024;
+ const int64_t mega = 1024*kilo;
+ const int64_t giga = 1024*mega;
char suffix = '\0';
- if (size >= 0) {
- if (!(size % 1024)) {
- suffix = 'k';
- divisor = 1024;
- } else if (!(size % 1024*1024)) {
- divisor = 1024*1024;
- suffix = 'm';
- } else if (!(size % 1024*1024*1024LL)) {
- divisor = 1024*1024*1024;
- suffix = 'g';
- }
+ if (size >= giga && !(size % giga)) {
+ divisor = giga;
+ suffix = 'g';
+ }
+ else if (size >= mega && !(size % mega)) {
+ divisor = mega;
+ suffix = 'm';
+ }
+ else if (size >= kilo && !(size % kilo)) {
+ divisor = kilo;
+ suffix = 'k';
}
if (divisor) {
snprintf(temp, sizeof temp, "%" PRId64 "%c", size/divisor, suffix);