Lines Matching refs:db

18 void handle_db_destroy(struct handle_db *db, void (*ptr_destructor)(void *ptr))  in handle_db_destroy()  argument
20 if (db) { in handle_db_destroy()
24 for (n = 0; n < db->max_ptrs; n++) in handle_db_destroy()
25 if (db->ptrs[n]) in handle_db_destroy()
26 ptr_destructor(db->ptrs[n]); in handle_db_destroy()
28 free(db->ptrs); in handle_db_destroy()
29 db->ptrs = NULL; in handle_db_destroy()
30 db->max_ptrs = 0; in handle_db_destroy()
34 bool handle_db_is_empty(struct handle_db *db) in handle_db_is_empty() argument
38 if (db) { in handle_db_is_empty()
39 for (n = 0; n < db->max_ptrs; n++) { in handle_db_is_empty()
40 if (db->ptrs[n]) in handle_db_is_empty()
47 int handle_get(struct handle_db *db, void *ptr) in handle_get() argument
53 if (!db || !ptr) in handle_get()
57 for (n = 0; n < db->max_ptrs; n++) { in handle_get()
58 if (!db->ptrs[n]) { in handle_get()
59 db->ptrs[n] = ptr; in handle_get()
65 if (db->max_ptrs) in handle_get()
66 new_max_ptrs = db->max_ptrs * 2; in handle_get()
69 p = realloc(db->ptrs, new_max_ptrs * sizeof(void *)); in handle_get()
72 db->ptrs = p; in handle_get()
73 memset(db->ptrs + db->max_ptrs, 0, in handle_get()
74 (new_max_ptrs - db->max_ptrs) * sizeof(void *)); in handle_get()
75 db->max_ptrs = new_max_ptrs; in handle_get()
78 db->ptrs[n] = ptr; in handle_get()
82 void *handle_put(struct handle_db *db, int handle) in handle_put() argument
86 if (!db || handle < 0 || (size_t)handle >= db->max_ptrs) in handle_put()
89 p = db->ptrs[handle]; in handle_put()
90 db->ptrs[handle] = NULL; in handle_put()
94 void *handle_lookup(struct handle_db *db, int handle) in handle_lookup() argument
96 if (!db || handle < 0 || (size_t)handle >= db->max_ptrs) in handle_lookup()
99 return db->ptrs[handle]; in handle_lookup()