- current_map = ZALLOC(cap_mapping);
- current_map->next = db->mappings;
- current_map->internal = internal;
- db->nr_mappings += 1;
- current_map->external = db->nr_mappings;
- db->mappings = current_map;
- return current_map->external;
+ return 0;
+}
+
+INLINE_CAP\
+(void)
+cap_add(cap *db,
+ void *internal)
+{
+ if (cap_external(db, internal) != 0) {
+ error("cap: attempting to add an object already in the data base");
+ }
+ else {
+ /* insert at the front making things in decending order */
+ cap_mapping *new_map = ZALLOC(cap_mapping);
+ new_map->next = db->mappings;
+ new_map->internal = internal;
+ db->nr_mappings += 1;
+ new_map->external = db->nr_mappings;
+ db->mappings = new_map;
+ }
+}
+
+INLINE_CAP\
+(void)
+cap_remove(cap *db,
+ void *internal)
+{
+ cap_mapping **current_map = &db->mappings;
+ while (*current_map != NULL) {
+ if ((*current_map)->internal == internal) {
+ cap_mapping *delete = *current_map;
+ *current_map = delete->next;
+ free(delete);
+ return;
+ }
+ current_map = &(*current_map)->next;
+ }
+ error("cap: attempt to remove nonexistant internal object");