+/**
+ * Adds a the 'alias' name to the api of 'name'.
+ * @params set the api set
+ * @param name the name of the api to alias
+ * @param alias the aliased name to add to the api of name
+ * @returns 0 in case of success or -1 in case
+ * of error with errno set:
+ * - ENOENT if the api doesn't exist
+ * - EEXIST if name (of alias) already registered
+ * - ENOMEM when out of memory
+ */
+int afb_apiset_add_alias(struct afb_apiset *set, const char *name, const char *alias)
+{
+ struct api_desc *api;
+ struct api_alias *ali, **pali;
+
+ /* check alias doesn't already exist */
+ if (search(set, alias)) {
+ ERROR("api of name %s already exists", alias);
+ errno = EEXIST;
+ goto error;
+ }
+
+ /* check aliased api exists */
+ api = search(set, name);
+ if (api == NULL) {
+ ERROR("api of name %s doesn't exists", name);
+ errno = ENOENT;
+ goto error;
+ }
+
+ /* allocates and init the struct */
+ ali = malloc(sizeof *ali + strlen(alias) + 1);
+ if (ali == NULL) {
+ ERROR("out of memory");
+ errno = ENOMEM;
+ goto error;
+ }
+ ali->api = api;
+ strcpy(ali->name, alias);
+
+ /* insert the alias in the sorted order */
+ pali = &set->aliases;
+ while(*pali && strcmp((*pali)->name, alias) < 0)
+ pali = &(*pali)->next;
+ ali->next = *pali;
+ *pali = ali;
+ return 0;
+error:
+ return -1;
+}
+
+int afb_apiset_is_alias(struct afb_apiset *set, const char *name)
+{
+ struct api_desc *api = searchrec(set, name);
+ return api && strcasecmp(api->name, name);
+}
+
+const char *afb_apiset_unalias(struct afb_apiset *set, const char *name)
+{
+ struct api_desc *api = searchrec(set, name);
+ return api ? api->name : NULL;
+}
+
+/**
+ * Delete from the 'set' the api of 'name'.
+ * @param set the set to be changed
+ * @param name the name of the API to remove
+ * @return 0 in case of success or -1 in case where the API doesn't exist.
+ */