aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils/ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'android/utils/ini.c')
-rw-r--r--android/utils/ini.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/android/utils/ini.c b/android/utils/ini.c
index ff4a8af..43f1321 100644
--- a/android/utils/ini.c
+++ b/android/utils/ini.c
@@ -298,8 +298,18 @@ EXIT:
return ini;
}
-int
-iniFile_saveToFile( IniFile* f, const char* filepath )
+/* Common routine for saving IniFile instance to the given file.
+ * Param:
+ * f - IniFile instance to save.
+ * filepath - Path to a file where to save the instance.
+ * strip - If 1, ignore (don't save) pairs with empty values. If 0, save all
+ * pairs found in the IniFile instance, including the ones that contain
+ * empty values.
+ * Returns:
+ * 0 on success, -1 on error (see errno for error code)
+ */
+static int
+iniFile_saveToFileCommon( IniFile* f, const char* filepath, int strip )
{
FILE* fp = fopen(filepath, "wt");
IniPair* pair = f->pairs;
@@ -313,11 +323,13 @@ iniFile_saveToFile( IniFile* f, const char* filepath )
}
for ( ; pair < pairEnd; pair++ ) {
- char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
- p = bufprint(temp, end, "%s = %s\n", pair->key, pair->value);
- if (fwrite(temp, p - temp, 1, fp) != 1) {
- result = -1;
- break;
+ if ((pair->value && *pair->value) || !strip) {
+ char temp[PATH_MAX], *p=temp, *end=p+sizeof(temp);
+ p = bufprint(temp, end, "%s = %s\n", pair->key, pair->value);
+ if (fwrite(temp, p - temp, 1, fp) != 1) {
+ result = -1;
+ break;
+ }
}
}
@@ -325,6 +337,33 @@ iniFile_saveToFile( IniFile* f, const char* filepath )
return result;
}
+int
+iniFile_saveToFile( IniFile* f, const char* filepath )
+{
+ return iniFile_saveToFileCommon(f, filepath, 0);
+}
+
+int
+iniFile_saveToFileClean( IniFile* f, const char* filepath )
+{
+ return iniFile_saveToFileCommon(f, filepath, 1);
+}
+
+int
+iniFile_getEntry(IniFile* f, int index, char** key, char** value)
+{
+ if (index >= f->numPairs) {
+ D("Index %d exceeds the number of ini file entries %d",
+ index, f->numPairs);
+ return -1;
+ }
+
+ *key = ASTRDUP(f->pairs[index].key);
+ *value = ASTRDUP(f->pairs[index].value);
+
+ return 0;
+}
+
char*
iniFile_getString( IniFile* f, const char* key, const char* defaultValue )
{