diff options
Diffstat (limited to 'android/utils/ini.c')
-rw-r--r-- | android/utils/ini.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/android/utils/ini.c b/android/utils/ini.c index 98355d4..56e40f2 100644 --- a/android/utils/ini.c +++ b/android/utils/ini.c @@ -15,12 +15,13 @@ #include <string.h> #include <limits.h> #include <errno.h> -#include "android_debug.h" +#include "android/utils/debug.h" +#include "android/utils/system.h" /* for ASTRDUP */ #include "osdep.h" /* W() is used to print warnings, D() to print debugging info */ #define W(...) dwarning(__VA_ARGS__) -#define D(...) VERBOSE_PRINT(vm_config,__VA_ARGS__) +#define D(...) VERBOSE_PRINT(avd_config,__VA_ARGS__) /* a simple .ini file parser and container for Android * no sections support. see android/utils/ini.h for @@ -42,18 +43,20 @@ iniFile_free( IniFile* i ) { int nn; for (nn = 0; nn < i->numPairs; nn++) { - free(i->pairs[nn].key); + AFREE(i->pairs[nn].key); i->pairs[nn].key = NULL; i->pairs[nn].value = NULL; } - free(i->pairs); - free(i); + AFREE(i->pairs); + AFREE(i); } static IniFile* iniFile_alloc( void ) { - IniFile* i = calloc(1, sizeof(*i)); + IniFile* i; + + ANEW0(i); return i; } @@ -64,17 +67,16 @@ iniFile_addPair( IniFile* i, const char* key, int keyLen, IniPair* pair; if (i->numPairs >= i->maxPairs) { - int oldMax = i->maxPairs; - int newMax = oldMax + (oldMax >> 1) + 4; - IniPair* newPairs = realloc(i->pairs, newMax*sizeof(newPairs[0])); + int oldMax = i->maxPairs; + int newMax = oldMax + (oldMax >> 1) + 4; - i->pairs = newPairs; + AARRAY_RENEW(i->pairs, newMax); i->maxPairs = newMax; } pair = i->pairs + i->numPairs; - pair->key = malloc(keyLen + valueLen + 2); + AARRAY_NEW(pair->key, keyLen + valueLen + 2); memcpy(pair->key, key, keyLen); pair->key[keyLen] = 0; @@ -269,12 +271,12 @@ iniFile_newFromFile( const char* filepath ) } /* read the file, add a sentinel at the end of it */ - text = malloc(size+1); + AARRAY_NEW(text, size+1); fread(text, 1, size, fp); text[size] = 0; ini = iniFile_newFromMemory(text, filepath); - free(text); + AFREE(text); EXIT: fclose(fp); @@ -289,7 +291,7 @@ iniFile_getString( IniFile* f, const char* key ) if (!val) return NULL; - return qemu_strdup(val); + return ASTRDUP(val); } int @@ -345,8 +347,8 @@ iniFile_getBoolean( IniFile* f, const char* key, const char* defaultValue ) int64_t iniFile_getDiskSize( IniFile* f, const char* key, const char* defaultValue ) { - const char* valStr = iniFile_getValue(f, key); - int64_t value = 0; + const char* valStr = iniFile_getValue(f, key); + int64_t value = 0; if (!valStr) valStr = defaultValue; @@ -364,3 +366,21 @@ iniFile_getDiskSize( IniFile* f, const char* key, const char* defaultValue ) } return value; } + +int64_t +iniFile_getInt64( IniFile* f, const char* key, int64_t defaultValue ) +{ + const char* valStr = iniFile_getValue(f, key); + int64_t value = defaultValue; + + if (valStr != NULL) { + char* end; + int64_t d; + + d = strtoll(valStr, &end, 10); + if (end != NULL && end[0] == 0) + value = d; + } + return value; +} + |