eina: add eina_file_stat helper function.

SVN revision: 68259
This commit is contained in:
Cedric BAIL 2012-02-22 10:24:11 +00:00
parent 127c3b81da
commit c461a7eed9
4 changed files with 40 additions and 8 deletions

View File

@ -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.

View File

@ -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:

View File

@ -22,6 +22,7 @@
#include <limits.h>
#include <time.h>
#include <sys/stat.h>
#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.

View File

@ -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
}