@@ -171,45 +171,43 @@ error_create_dirs:
return r;
}
-GKeyFile *storage_open(const char *imsi, const char *store)
+char *storage_get_file_path(const char *imsi, const char *store)
{
- GKeyFile *keyfile;
- char *path;
-
if (store == NULL)
return NULL;
if (imsi)
- path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
+ return l_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
else
- path = g_strdup_printf(STORAGEDIR "/%s", store);
+ return l_strdup_printf(STORAGEDIR "/%s", store);
+}
- keyfile = g_key_file_new();
+GKeyFile *storage_open(const char *imsi, const char *store)
+{
+ GKeyFile *keyfile;
+ char *path = storage_get_file_path(imsi, store);
- if (path) {
- g_key_file_load_from_file(keyfile, path, 0, NULL);
- g_free(path);
- }
+ if (!path)
+ return NULL;
+
+ keyfile = g_key_file_new();
+ g_key_file_load_from_file(keyfile, path, 0, NULL);
+ l_free(path);
return keyfile;
}
void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
{
- char *path;
+ char *path = storage_get_file_path(imsi, store);
char *data;
gsize length = 0;
- if (imsi)
- path = g_strdup_printf(STORAGEDIR "/%s/%s", imsi, store);
- else
- path = g_strdup_printf(STORAGEDIR "/%s", store);
-
if (path == NULL)
return;
if (create_dirs(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
- g_free(path);
+ l_free(path);
return;
}
@@ -218,7 +216,7 @@ void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile)
g_file_set_contents(path, data, length, NULL);
g_free(data);
- g_free(path);
+ l_free(path);
}
void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,
@@ -32,6 +32,7 @@ ssize_t write_file(const unsigned char *buffer, size_t len, mode_t mode,
const char *path_fmt, ...)
__attribute__((format(printf, 4, 5)));
+char *storage_get_file_path(const char *imsi, const char *store);
GKeyFile *storage_open(const char *imsi, const char *store);
void storage_sync(const char *imsi, const char *store, GKeyFile *keyfile);
void storage_close(const char *imsi, const char *store, GKeyFile *keyfile,