// TODO: list.size is really the next id, not size if list items are deleted
+#define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
*(unsigned int *)a->mv_data > *(unsigned int *)b->mv_data;
}
-dbindex *dbindex_open(const char *path) {
+char *dbindex_home(void) {
+ char *home = getenv("HOME");
+ char *path = NULL;
+
+ if (!home || asprintf(&path, "%s/.local/lib/playerz/index", home) < 0)
+ abort();
+
+ return path;
+}
+
+dbindex *dbindex_open(const char *ipath) {
dbindex *db = calloc(sizeof(*db), 1);
int res;
MDB_txn *tx;
+ char *dpath = ipath ? NULL : dbindex_home();
+ const char *path = ipath ? ipath : dpath;
res = mdb_env_create(&db->env);
if (res)
}
printf("dbindex open, disk.id=%d list.id=%d file.id=%d\n", db->diskid, db->listid, db->fileid);
+ free(dpath);
return db;
fail:
if (db->env)
mdb_env_close(db->env);
free(db);
+ free(dpath);
+
return NULL;
}
typedef struct MDB_txn dbtxn;
typedef struct dbscan dbscan;
+// database location, default is ~/.local/lib/playerz/db. free after use.
+char *dbindex_home(void);
+
dbindex *dbindex_open(const char *path);
void dbindex_close(dbindex *db);
int dbscan_list_entry_seq(dbscan *scan);
dbid_t dbscan_list_entry_listid(dbscan *scan);
-#define MAIN_INDEX "/home/notzed/playerz.db"
+#define MAIN_INDEX NULL