aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/storage.h2
-rw-r--r--src/storage_sqlite.c31
-rw-r--r--src/storage_sqlite.h5
3 files changed, 27 insertions, 11 deletions
diff --git a/src/storage.h b/src/storage.h
index 2bb2fff..e10ee87 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -17,7 +17,7 @@ enum storage_type {
struct storage_settings {
enum storage_type type;
union {
- struct storage_settings_sqlite sqlite;
+ struct storage_settings_sqlite *sqlite;
};
};
diff --git a/src/storage_sqlite.c b/src/storage_sqlite.c
index abde621..c56aef5 100644
--- a/src/storage_sqlite.c
+++ b/src/storage_sqlite.c
@@ -17,21 +17,40 @@
#include <stdlib.h>
#include <string.h>
+struct storage_settings_sqlite {
+ char *path;
+};
+
int storage_settings_create_sqlite(struct storage_settings *settings, const char *path)
{
- settings->sqlite.path = strdup(path);
- if (!settings->sqlite.path) {
- log_errno("strdup");
+ struct storage_settings_sqlite *sqlite;
+
+ sqlite = malloc(sizeof(struct storage_settings_sqlite));
+ if (!sqlite) {
+ log_errno("malloc");
return -1;
}
+ sqlite->path = strdup(path);
+ if (!sqlite->path) {
+ log_errno("strdup");
+ goto free;
+ }
+
settings->type = STORAGE_TYPE_SQLITE;
+ settings->sqlite = sqlite;
return 0;
+
+free:
+ free(sqlite);
+
+ return -1;
}
void storage_settings_destroy_sqlite(const struct storage_settings *settings)
{
- free(settings->sqlite.path);
+ free(settings->sqlite->path);
+ free(settings->sqlite);
}
struct storage_sqlite {
@@ -131,7 +150,7 @@ int storage_create_sqlite(struct storage *storage, const struct storage_settings
{
int ret = 0;
- log("Using SQLite database at %s\n", settings->sqlite.path);
+ log("Using SQLite database at %s\n", settings->sqlite->path);
storage->sqlite = malloc(sizeof(storage->sqlite));
if (!storage->sqlite) {
@@ -142,7 +161,7 @@ int storage_create_sqlite(struct storage *storage, const struct storage_settings
ret = sqlite_init();
if (ret < 0)
goto free;
- ret = sqlite_open_rw(settings->sqlite.path, &storage->sqlite->db);
+ ret = sqlite_open_rw(settings->sqlite->path, &storage->sqlite->db);
if (ret < 0)
goto destroy;
ret = storage_prepare_sqlite(storage->sqlite);
diff --git a/src/storage_sqlite.h b/src/storage_sqlite.h
index b7f0bb1..30a5dd4 100644
--- a/src/storage_sqlite.h
+++ b/src/storage_sqlite.h
@@ -9,10 +9,7 @@
#define __STORAGE_SQLITE_H__
struct storage_settings;
-
-struct storage_settings_sqlite {
- char *path;
-};
+struct storage_settings_sqlite;
struct storage;
struct storage_sqlite;