+typedef struct _myconn {
+ struct _myconn *next;
+ DB *db;
+ char *path;
+ bool modify;
+} MYCONN;
+
+static MYCONN *connections;
+
+static void
+cleanup(void)
+{
+ while (connections != 0) {
+ _nc_db_close(connections->db);
+ }
+}
+
+static DB *
+find_connection(const char *path, bool modify)
+{
+ DB *result = 0;
+ MYCONN *p;
+
+ for (p = connections; p != 0; p = p->next) {
+ if (!strcmp(p->path, path) && p->modify == modify) {
+ result = p->db;
+ break;
+ }
+ }
+
+ return result;
+}
+
+static void
+drop_connection(DB * db)
+{
+ MYCONN *p, *q;
+
+ for (p = connections, q = 0; p != 0; q = p, p = p->next) {
+ if (p->db == db) {
+ if (q != 0)
+ q->next = p->next;
+ else
+ connections = p->next;
+ free(p->path);
+ free(p);
+ break;
+ }
+ }
+}
+
+static void
+make_connection(DB * db, const char *path, bool modify)
+{
+ MYCONN *p = typeCalloc(MYCONN, 1);
+
+ if (p != 0) {
+ p->db = db;
+ p->path = strdup(path);
+ p->modify = modify;
+ if (p->path != 0) {
+ p->next = connections;
+ connections = p;
+ } else {
+ free(p);
+ }
+ }
+}
+