+/**
+ * @brief Get the path to the database
+ */
+static int get_database_path(char *buffer, size_t size)
+{
+ static const char dbfile[] = DBFILE;
+
+ char *home, *config;
+ int rc;
+
+ config = secure_getenv("XDG_CONFIG_HOME");
+ if (config)
+ rc = snprintf(buffer, size, "%s/.config/%s", home, dbfile);
+ else
+ {
+ home = secure_getenv("HOME");
+ if (home)
+ rc = snprintf(buffer, size, "%s/.config/%s", home, dbfile);
+ else
+ {
+ struct passwd *pwd = getpwuid(getuid());
+ if (pwd)
+ rc = snprintf(buffer, size, "%s/.config/%s", result->pw_dir, dbfile);
+ else
+ rc = snprintf(buffer, size, "/home/%d/.config/%s", (int)getuid(), dbfile);
+ }
+ }
+ return rc;
+}
+