diff options
-rw-r--r-- | db.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -1,10 +1,6 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/types.h> #include <unistd.h> +#include <glib/gstdio.h> #include <glib/gprintf.h> #include "db.h" @@ -53,20 +49,20 @@ static int db_create_tables() { int db_open() { int rc; - int configfound; + int datafound; char *dbfile; - char *configdir; + char *datadir; - configdir = g_strdup_printf("%s/walls", g_get_user_config_dir()); - if(access(configdir, F_OK) == -1 && g_mkdir_with_parents(configdir, 0700) == -1) { - g_free(configdir); + datadir = g_strdup_printf("%s/walls", g_get_user_data_dir()); + if(access(datadir, F_OK) == -1 && g_mkdir_with_parents(datadir, 0700) == -1) { + g_free(datadir); return 0; } - g_free(configdir); - dbfile = g_strdup_printf("%s/walls/db", g_get_user_config_dir()); - printf("db file: %s\n", dbfile); - configfound = access(dbfile, F_OK) == 0; + dbfile = g_strdup_printf("%s/db", datadir); + datafound = g_access(dbfile, F_OK) == 0; + + g_free(datadir); rc = sqlite3_open(dbfile, &db); g_free(dbfile); @@ -75,7 +71,7 @@ int db_open() { return 0; } - if(!configfound && !db_create_tables()) { + if(!datafound && !db_create_tables()) { db_close(); return 0; } |