eina: introduce Eina_Stat to prevent issue when building with different config option.

SVN revision: 68315
This commit is contained in:
Cedric BAIL 2012-02-23 11:45:25 +00:00
parent 6107c5b96e
commit b693dd6035
2 changed files with 73 additions and 14 deletions

View File

@ -91,6 +91,12 @@
*/
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
@ -149,6 +155,30 @@ struct _Eina_File_Direct_Info
char path[EINA_PATH_MAX]; /**< the path */
};
/**
* @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.
@ -262,7 +292,7 @@ EAPI Eina_Iterator *eina_file_stat_ls(const char *dir) EINA_WARN_UNUSED_RESULT E
* @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

View File

@ -362,14 +362,14 @@ _eina_file_direct_ls_iterator_free(Eina_File_Direct_Iterator *it)
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;
}
@ -1276,20 +1276,21 @@ eina_file_mmap_faulty(void *addr, long page_size)
}
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)
@ -1299,23 +1300,51 @@ eina_file_stat(void *container, Eina_File_Direct_Info *info, struct stat *buf)
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;
}