eina: add eina_file_stat helper function.
authorCedric BAIL <cedric.bail@free.fr>
Wed, 22 Feb 2012 10:24:11 +0000 (10:24 +0000)
committerCedric BAIL <cedric.bail@free.fr>
Wed, 22 Feb 2012 10:24:11 +0000 (10:24 +0000)
SVN revision: 68259

legacy/eina/ChangeLog
legacy/eina/NEWS
legacy/eina/src/include/eina_file.h
legacy/eina/src/lib/eina_file.c

index fc31b21..265a958 100644 (file)
 
        * Fix forgotten initialization of eina list count during eina_list_split_list.
 
+2012-02-22  Cedric Bail
+
+       * Add eina_file_stat.
index 49e2178..6fc1aff 100644 (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:
 
index 422fb65..090d923 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <limits.h>
 #include <time.h>
+#include <sys/stat.h>
 
 #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.
  *
index 01a6c02..5a20bce 100644 (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
+}