+/**
+ * global apis
+ */
+static struct api_desc *all_apis;
+
+/**
+ * global classes
+ */
+static struct api_class *all_classes;
+
+/**
+ * Ensure enough room in 'array' for 'count' items
+ */
+static int api_array_ensure_count(struct api_array *array, int count)
+{
+ int c;
+ void **anys;
+
+ c = (count + INCR - 1) & ~(INCR - 1);
+ anys = realloc(array->anys, c * sizeof *anys);
+ if (!anys) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ array->count = count;
+ array->anys = anys;
+ return 0;
+}
+
+/**
+ * Insert in 'array' the item 'any' at the 'index'
+ */
+static int api_array_insert(struct api_array *array, void *any, int index)
+{
+ int n = array->count;
+
+ if (api_array_ensure_count(array, n + 1) < 0)
+ return -1;
+
+ while (index < n) {
+ array->anys[n] = array->anys[n - 1];
+ n--;
+ }
+
+ array->anys[index] = any;
+ return 0;
+}
+
+/**
+ * Add the item 'any' to the 'array'
+ */
+static int api_array_add(struct api_array *array, void *any)
+{
+ int i, n = array->count;
+
+ for (i = 0 ; i < n ; i++) {
+ if (array->anys[i] == any)
+ return 0;
+ }
+
+ if (api_array_ensure_count(array, n + 1) < 0)
+ return -1;
+
+ array->anys[n] = any;
+ return 0;
+}
+
+/**
+ * Delete the 'api' from the 'array'
+ * Returns 1 if delete or 0 if not found
+ */
+static int api_array_del(struct api_array *array, void *any)
+{
+ int i = array->count;
+ while (i) {
+ if (array->anys[--i] == any) {
+ array->anys[i] = array->anys[--array->count];
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/**
+ * Search the class of 'name' and return it.
+ * In case where the class of 'namle' isn't found, it returns
+ * NULL when 'create' is null or a fresh created instance if 'create' isn't
+ * zero (but NULL on allocation failure).
+ */
+static struct api_class *class_search(const char *name, int create)
+{
+ struct api_class *c;
+
+ for (c= all_classes ; c ; c = c->next) {
+ if (!strcasecmp(name, c->name))
+ return c;
+ }
+
+ if (!create)
+ return NULL;
+
+ c = calloc(1, strlen(name) + sizeof *c);
+ if (!c)
+ errno = ENOMEM;
+ else {
+ strcpy(c->name, name);
+ c->next = all_classes;
+ all_classes = c;
+ }
+ return c;
+}
+