Lines Matching refs:db
55 struct db_names *db; in db_names_alloc() local
57 db = malloc(sizeof(*db)); in db_names_alloc()
58 if (!db) in db_names_alloc()
61 memset(db, 0, sizeof(*db)); in db_names_alloc()
63 db->size = MAX_ENTRIES; in db_names_alloc()
64 db->hash = malloc(sizeof(struct db_entry *) * db->size); in db_names_alloc()
65 memset(db->hash, 0, sizeof(struct db_entry *) * db->size); in db_names_alloc()
67 return db; in db_names_alloc()
70 int db_names_load(struct db_names *db, const char *path) in db_names_load() argument
104 entry->next = db->hash[id & (db->size - 1)]; in db_names_load()
105 db->hash[id & (db->size - 1)] = entry; in db_names_load()
114 void db_names_free(struct db_names *db) in db_names_free() argument
118 if (!db) in db_names_free()
121 for (i = 0; i < db->size; i++) { in db_names_free()
122 struct db_entry *entry = db->hash[i]; in db_names_free()
133 free(db->hash); in db_names_free()
134 free(db); in db_names_free()
137 char *id_to_name(struct db_names *db, int id, char *name) in id_to_name() argument
141 if (!db) in id_to_name()
144 entry = db->hash[id & (db->size - 1)]; in id_to_name()
157 int name_to_id(struct db_names *db, int *id, const char *name) in name_to_id() argument
162 if (!db) in name_to_id()
165 if (db->cached && strcmp(db->cached->name, name) == 0) { in name_to_id()
166 *id = db->cached->id; in name_to_id()
170 for (i = 0; i < db->size; i++) { in name_to_id()
171 entry = db->hash[i]; in name_to_id()
176 db->cached = entry; in name_to_id()