SEXP_datatypePtr_t *SEXP_datatype_add(SEXP_datatypeTbl_t *t, char *n) { void *r; struct rbt_str_node *node = NULL; if (t == NULL || n == NULL) { return NULL; } SEXP_datatype_once(); if (rbt_str_add(t->tree, n, NULL) != 0) return(NULL); /* * XXX: consider adding a version of rbt_str_add that returns * the node pointer, so that we don't have perform the * following search operation. */ if (rbt_str_getnode(t->tree, n, &node) != 0) return(NULL); r = node; return((SEXP_datatypePtr_t *)r); }
void oval_string_map_put(struct oval_string_map *map, const char *key, void *val) { char *key_copy; assume_d(map != NULL, /* void */); assume_d(key != NULL, /* void */); if (rbt_str_add((rbt_t *)map, key_copy = strdup(key), val) != 0) { dW("rbt_str_add: non-zero return code"); oscap_free(key_copy); } }
void oval_string_map_put_string(struct oval_string_map *map, const char *key, const char *val) { char *str = strdup(val), *key_copy; assume_d(map != NULL, /* void */); assume_d(key != NULL, /* void */); if (rbt_str_add((rbt_t *)map, key_copy = strdup(key), str) == 0) return; else { oscap_free(str); oscap_free(key_copy); } return; }
int probe_rcache_sexp_add(probe_rcache_t *cache, const SEXP_t *id, SEXP_t *item) { SEXP_t *r; char *k; assume_d(cache != NULL, -1); assume_d(id != NULL, -1); assume_d(item != NULL, -1); k = SEXP_string_cstr(id); r = SEXP_ref(item); if (rbt_str_add(cache->tree, k, (void *)r) != 0) { SEXP_free(r); free(k); return (-1); } return (0); }
SEXP_datatypePtr_t *SEXP_datatype_add(SEXP_datatypeTbl_t *t, char *n, SEXP_datatype_t *d, void *l) { void *r; struct rbt_str_node *node = NULL; assume_d(t != NULL, NULL); assume_d(n != NULL, NULL); SEXP_datatype_once(); /* * Check whether flags & passed values are meaningful */ if (l != NULL && (d->dt_flg & SEXP_DTFLG_LOCALDATA) == 0) { errno = EINVAL; return(NULL); } if (rbt_str_add(t->tree, n, d) != 0) return(NULL); /* * XXX: consider adding a version of rbt_str_add that returns * the node pointer, so that we don't have perform the * following search operation. */ if (rbt_str_getnode(t->tree, n, &node) != 0) return(NULL); if (d != NULL) { /* * If DTFLG_LOCALDATA is set, allocate a new extended pointer * and return it with `l' set as the local data pointer. */ if (d->dt_flg & SEXP_DTFLG_LOCALDATA) { struct SEXP_datatype_extptr *eptr = NULL; /* * Ensure that we can use the lowest bit for the extended * pointer flag. In the case we are returning the "normal" * pointer, the memory is already aligned because it's a * pointer into a red-black tree node + 2*sizeof(void *) * offset. The red-black tree implmentation allocates nodes * aligned to sizeof(void *) bytes. */ if (posix_memalign((void **)(void *)(&eptr), SEXP_DATATYPEPTR_ALIGN, sizeof(struct SEXP_datatype_extptr)) != 0) { return(NULL); } eptr->n = node; eptr->l = l; r = (void *)((uintptr_t)(eptr)|1); } else r = node; } else r = node; return((SEXP_datatypePtr_t *)r); }