\r
if (!*rootp) {\r
*rootp = malloc(sizeof(cl_fmap_t));\r
+ if (!*rootp)\r
+ return NULL;\r
cl_fmap_init((cl_fmap_t *) *rootp, fcompare);\r
}\r
\r
compare = compar;\r
item = malloc(sizeof(cl_fmap_item_t));\r
+ if (!item)\r
+ return NULL;\r
+\r
map_item = cl_fmap_insert((cl_fmap_t *) *rootp, key, item);\r
- if (map_item != item) {\r
+ if (map_item != item)\r
free(item);\r
- return (void *) map_item->p_key;\r
- }\r
\r
- return (void *) key;\r
+ return (void *) &map_item->p_key;\r
}\r
\r
void *tfind(const void *key, void *const *rootp,\r
if (item == cl_fmap_end((cl_fmap_t *) *rootp))\r
return NULL;\r
\r
- return (void *) item->p_key;\r
+ return (void *) &item->p_key;\r
}\r
\r
+/*\r
+ * Returns NULL if item is not found, or the item itself. This differs\r
+ * from the tdelete call by not retuning the parent item, but works if\r
+ * the user is only checking against NULL.\r
+ */\r
void *tdelete(const void *key, void **rootp,\r
int (*compar)(const void *, const void *))\r
{\r