From c907e4d8322af9c35b3f834f8bb0d86efab2ddf4 Mon Sep 17 00:00:00 2001 From: cedric Date: Wed, 22 Feb 2012 10:24:11 +0000 Subject: [PATCH] eina: add eina_file_stat helper function. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@68259 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- ChangeLog | 3 +++ NEWS | 1 + src/include/eina_file.h | 18 ++++++++++++++++++ src/lib/eina_file.c | 26 ++++++++++++++++++-------- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc31b21..265a958 100644 --- a/ChangeLog +++ b/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/NEWS b/NEWS index 49e2178..6fc1aff 100644 --- a/NEWS +++ b/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/src/include/eina_file.h b/src/include/eina_file.h index 422fb65..090d923 100644 --- a/src/include/eina_file.h +++ b/src/include/eina_file.h @@ -22,6 +22,7 @@ #include #include +#include #include "eina_types.h" #include "eina_array.h" @@ -247,6 +248,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/src/lib/eina_file.c b/src/lib/eina_file.c index 01a6c02..5a20bce 100644 --- a/src/lib/eina_file.c +++ b/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 +} -- 2.7.4