From: cedric Date: Fri, 20 Nov 2009 20:46:24 +0000 (+0000) Subject: * eina_module: Add eina_module_find. Thanks to Fabiano Fidêncio . git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@43847 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/AUTHORS b/AUTHORS index febfd76..eae0bfb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,3 +12,4 @@ Albin "Lutin" Tonnerre Andre Dieb Raphael Kubo da Costa Gustavo Chaves +Fabiano Fidêncio diff --git a/src/include/eina_module.h b/src/include/eina_module.h index eca37c4..37c4e3c 100644 --- a/src/include/eina_module.h +++ b/src/include/eina_module.h @@ -70,6 +70,7 @@ EAPI Eina_Array * eina_module_list_get(Eina_Array *array, const char *path, unsi EAPI void eina_module_list_load(Eina_Array *list) EINA_ARG_NONNULL(1); EAPI void eina_module_list_unload(Eina_Array *list) EINA_ARG_NONNULL(1); EAPI void eina_module_list_flush(Eina_Array *list) EINA_ARG_NONNULL(1); +EAPI Eina_Module * eina_module_find(Eina_Array *array, char *module) EINA_ARG_NONNULL(1, 2); /** * @} diff --git a/src/lib/eina_module.c b/src/lib/eina_module.c index 78eae7c..de5d148 100644 --- a/src/lib/eina_module.c +++ b/src/lib/eina_module.c @@ -547,6 +547,37 @@ EAPI Eina_Array * eina_module_list_get(Eina_Array *array, const char *path, unsi } /** + * @brief Find an module in array. + * + * @param array The array to find the module. + * @param module The name of module to be searched; + * + * This function finds an @p module in an @p array; + * If the element is found return the module else NULL. + */ +EAPI Eina_Module * +eina_module_find(Eina_Array *array, char *module) +{ + unsigned int i; + Eina_Array_Iterator iterator; + Eina_Module *m; + + EINA_ARRAY_ITER_NEXT(array, i, m, iterator) + { + const char *file_m; + ssize_t len; + + file_m = basename(eina_module_file_get(m)); + len = strlen(file_m); + len -= sizeof(MODULE_EXTENSION) - 1; + if (len <= 0) continue; + if (!strncmp(module, file_m, len)) return m; + } + + return NULL; +} + +/** * Load every module on the list of modules * @param array The array of modules to load */