diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog index fc31b21ce8..265a958bad 100644 --- a/legacy/eina/ChangeLog +++ b/legacy/eina/ChangeLog @@ -222,3 +222,6 @@ * Fix forgotten initialization of eina list count during eina_list_split_list. +2012-02-22 Cedric Bail + + * Add eina_file_stat. diff --git a/legacy/eina/NEWS b/legacy/eina/NEWS index 49e2178b73..6fc1affa92 100644 --- a/legacy/eina/NEWS +++ b/legacy/eina/NEWS @@ -15,6 +15,7 @@ Additions: * Added eina_inarray data type * Added eina_value data type (generic value storage) * Added eina_model data type (generic hierarchy data access) + * Add eina_file_stat. Fixes: diff --git a/legacy/eina/src/include/eina_file.h b/legacy/eina/src/include/eina_file.h index 422fb65b57..090d923fb5 100644 --- a/legacy/eina/src/include/eina_file.h +++ b/legacy/eina/src/include/eina_file.h @@ -22,6 +22,7 @@ #include #include +#include #include "eina_types.h" #include "eina_array.h" @@ -246,6 +247,23 @@ EAPI Eina_Iterator *eina_file_ls(const char *dir) EINA_WARN_UNUSED_RESULT EINA_A */ EAPI Eina_Iterator *eina_file_stat_ls(const char *dir) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; +/** + * @brief Use information provided by Eina_Iterator of eina_file_stat_ls or eina_file_direct_ls + * to call stat in the most efficient way on your system. + * + * @param container The container returned by the Eina_Iterator. + * @param info The content of the curently Eina_File_Direct_Info provided by the Eina_Iterator + * @param buf Where to put the result of the stat + * @return On success 0 is returned, On error -1 is returned and errno is set appropriatly. + * + * This function call fstatat or stat depending on what your system support. This make it efficient and simple + * to use on your side without complex detection already done inside Eina on what the system can do. + * + * @see eina_file_direct_ls() + * @see eina_file_stat_ls() + */ +EAPI int eina_file_stat(void *container, Eina_File_Direct_Info *info, struct stat *buf) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2, 3); + /** * @brief Get an iterator to list the content of a directory, with direct * information. diff --git a/legacy/eina/src/lib/eina_file.c b/legacy/eina/src/lib/eina_file.c index 01a6c020d3..5a20bcee5c 100644 --- a/legacy/eina/src/lib/eina_file.c +++ b/legacy/eina/src/lib/eina_file.c @@ -369,14 +369,7 @@ _eina_file_stat_ls_iterator_next(Eina_File_Direct_Iterator *it, void **data) if (it->info.type == EINA_FILE_UNKNOWN) { -#ifdef HAVE_FSTATAT - int fd; - - fd = dirfd(it->dirp); - if (fstatat(fd, it->info.path + it->info.name_start, &st, 0)) -#else - if (stat(it->info.path, &st)) -#endif + if (eina_file_stat(it->dirp, &it->info, &st)) it->info.type = EINA_FILE_UNKNOWN; else { @@ -1301,3 +1294,20 @@ eina_file_mmap_faulty(void *addr, long page_size) eina_lock_release(&_eina_file_lock_cache); } +EAPI int +eina_file_stat(void *container, Eina_File_Direct_Info *info, struct stat *buf) +{ +#ifdef HAVE_FSTATAT + int fd; +#endif + + EINA_SAFETY_ON_NULL_RETURN_VAL(info, -1); + EINA_SAFETY_ON_NULL_RETURN_VAL(buf, -1); + +#ifdef HAVE_FSTATAT + fd = dirfd(container); + return fstatat(fd, info->path + info->name_start, buf, 0); +#else + return stat(it->info.path, buf); +#endif +}