typedef struct _Eina_File_Direct_Info Eina_File_Direct_Info;
/**
+ * @typedef Eina_Stat
+ * A typedef to #_Eina_Stat.
+ */
+typedef struct _Eina_Stat Eina_Stat;
+
+/**
* @typedef Eina_File_Dir_List_Cb
* Type for a callback to be called when iterating over the files of a
* directory.
};
/**
+ * @struct _Eina_Stat
+ * A structure to store informations of a path.
+ */
+struct _Eina_Stat
+{
+ unsigned long int dev;
+ unsigned long int ino;
+ unsigned int mode;
+ unsigned int nlink;
+ unsigned int uid;
+ unsigned int gid;
+ unsigned long int rdev;
+ unsigned long int size;
+ unsigned long int blksize;
+ unsigned long int blocks;
+ unsigned long int atime;
+ unsigned long int atimensec;
+ unsigned long int mtime;
+ unsigned long int mtimensec;
+ unsigned long int ctime;
+ unsigned long int ctimensec;
+};
+
+/**
* @def EINA_FILE_DIR_LIST_CB
* @brief cast to an #Eina_File_Dir_List_Cb.
*
* @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);
+EAPI int eina_file_statat(void *container, Eina_File_Direct_Info *info, Eina_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
static Eina_Bool
_eina_file_stat_ls_iterator_next(Eina_File_Direct_Iterator *it, void **data)
{
- struct stat st;
+ Eina_Stat st;
if (!_eina_file_direct_ls_iterator_next(it, data))
return EINA_FALSE;
if (it->info.type == EINA_FILE_UNKNOWN)
{
- if (eina_file_stat(it->dirp, &it->info, &st) != 0)
+ if (eina_file_statat(it->dirp, &it->info, &st) != 0)
it->info.type = EINA_FILE_UNKNOWN;
}
}
EAPI int
-eina_file_stat(void *container, Eina_File_Direct_Info *info, struct stat *buf)
+eina_file_statat(void *container, Eina_File_Direct_Info *info, Eina_Stat *st)
{
+ 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);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(st, -1);
#ifdef HAVE_FSTATAT
fd = dirfd(container);
- if (fstatat(fd, info->path + info->name_start, buf, 0))
+ if (fstatat(fd, info->path + info->name_start, &buf, 0))
#else
- if (stat(info->path, buf))
+ if (stat(info->path, &buf))
#endif
{
if (info->type != EINA_FILE_LNK)
if (info->type == EINA_FILE_UNKNOWN)
{
- if (S_ISREG(buf->st_mode))
+ if (S_ISREG(buf.st_mode))
info->type = EINA_FILE_REG;
- else if (S_ISDIR(buf->st_mode))
+ else if (S_ISDIR(buf.st_mode))
info->type = EINA_FILE_DIR;
- else if (S_ISCHR(buf->st_mode))
+ else if (S_ISCHR(buf.st_mode))
info->type = EINA_FILE_CHR;
- else if (S_ISBLK(buf->st_mode))
+ else if (S_ISBLK(buf.st_mode))
info->type = EINA_FILE_BLK;
- else if (S_ISFIFO(buf->st_mode))
+ else if (S_ISFIFO(buf.st_mode))
info->type = EINA_FILE_FIFO;
- else if (S_ISLNK(buf->st_mode))
+ else if (S_ISLNK(buf.st_mode))
info->type = EINA_FILE_LNK;
- else if (S_ISSOCK(buf->st_mode))
+ else if (S_ISSOCK(buf.st_mode))
info->type = EINA_FILE_SOCK;
else
info->type = EINA_FILE_UNKNOWN;
}
+ st->dev = buf.st_dev;
+ st->ino = buf.st_ino;
+ st->mode = buf.st_mode;
+ st->nlink = buf.st_nlink;
+ st->uid = buf.st_uid;
+ st->gid = buf.st_gid;
+ st->rdev = buf.st_rdev;
+ st->size = buf.st_size;
+ st->blksize = buf.st_blksize;
+ st->blocks = buf.st_blocks;
+ st->atime = buf.st_atime;
+ st->mtime = buf.st_mtime;
+ st->ctime = buf.st_ctime;
+#ifdef _STAT_VER_LINUX
+# if (defined __USE_MISC && defined st_mtime)
+ st->atimensec = buf.st_atim.tv_nsec;
+ st->mtimensec = buf.st_mtim.tv_nsec;
+ st->ctimensec = buf.st_ctim.tv_nsec;
+# else
+ st->atimensec = buf.st_atimensec;
+ st->mtimensec = buf.st_mtimensec;
+ st->ctimensec = buf.st_ctimensec;
+# endif
+#else
+ st->atimensec = 0;
+ st->mtimensec = 0;
+ st->ctimensec = 0;
+#endif
return 0;
}