forked from enlightenment/efl
* eina: rename ecore_file_ls_iterator to eina_file_ls.
SVN revision: 50002
This commit is contained in:
parent
9560d51241
commit
d4059c7107
|
@ -29,47 +29,6 @@
|
||||||
int _ecore_file_log_dom = -1;
|
int _ecore_file_log_dom = -1;
|
||||||
static int _ecore_file_init_count = 0;
|
static int _ecore_file_init_count = 0;
|
||||||
|
|
||||||
static Eina_Bool
|
|
||||||
_ecore_file_ls_iterator_next(Ecore_File_Iterator *it, void **data)
|
|
||||||
{
|
|
||||||
struct dirent *dp;
|
|
||||||
char *name;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
dp = readdir(it->dirp);
|
|
||||||
if (!dp) return EINA_FALSE;
|
|
||||||
}
|
|
||||||
while (!strcmp(dp->d_name, ".")
|
|
||||||
|| !strcmp(dp->d_name, ".."));
|
|
||||||
|
|
||||||
length = strlen(dp->d_name);
|
|
||||||
name = alloca(length + 2 + it->length);
|
|
||||||
|
|
||||||
memcpy(name, it->dir, it->length);
|
|
||||||
memcpy(name + it->length, "/", 1);
|
|
||||||
memcpy(name + it->length + 1, dp->d_name, length + 1);
|
|
||||||
|
|
||||||
*data = (char*) eina_stringshare_add(name);
|
|
||||||
return EINA_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
_ecore_file_ls_iterator_container(Ecore_File_Iterator *it)
|
|
||||||
{
|
|
||||||
return it->dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_ecore_file_ls_iterator_free(Ecore_File_Iterator *it)
|
|
||||||
{
|
|
||||||
closedir(it->dirp);
|
|
||||||
|
|
||||||
EINA_MAGIC_SET(&it->iterator, 0);
|
|
||||||
free(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* externally accessible functions */
|
/* externally accessible functions */
|
||||||
/**
|
/**
|
||||||
* Initialize Ecore_File and the services it will use. Call this function
|
* Initialize Ecore_File and the services it will use. Call this function
|
||||||
|
@ -740,46 +699,6 @@ ecore_file_ls(const char *dir)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an iterator to list the content of a directory. Give a chance to interrupt it
|
|
||||||
* and make it completly asynchrone.
|
|
||||||
* The iterator will walk over '.' and '..' without returning them.
|
|
||||||
* @param dir The name of the directory to list
|
|
||||||
* @return Return an Eina_Iterator that will walk over the files and directory in the pointed
|
|
||||||
* directory. On failure it will return NULL.
|
|
||||||
*/
|
|
||||||
EAPI Eina_Iterator *
|
|
||||||
ecore_file_ls_iterator(const char *dir)
|
|
||||||
{
|
|
||||||
Ecore_File_Iterator *it;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
if (!dir) return NULL;
|
|
||||||
|
|
||||||
length = strlen(dir);
|
|
||||||
|
|
||||||
it = malloc(sizeof (Ecore_File_Iterator) + length);
|
|
||||||
if (!it) return NULL;
|
|
||||||
|
|
||||||
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
|
|
||||||
|
|
||||||
it->dirp = opendir(dir);
|
|
||||||
if (!it->dirp)
|
|
||||||
{
|
|
||||||
free(it);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(it->dir, dir, length + 1);
|
|
||||||
it->length = length;
|
|
||||||
|
|
||||||
it->iterator.next = FUNC_ITERATOR_NEXT(_ecore_file_ls_iterator_next);
|
|
||||||
it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_ecore_file_ls_iterator_container);
|
|
||||||
it->iterator.free = FUNC_ITERATOR_FREE(_ecore_file_ls_iterator_free);
|
|
||||||
|
|
||||||
return &it->iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME: To be documented.
|
* FIXME: To be documented.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,17 +82,6 @@ struct _Ecore_File_Monitor
|
||||||
Ecore_File *files;
|
Ecore_File *files;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _Ecore_File_Iterator Ecore_File_Iterator;
|
|
||||||
struct _Ecore_File_Iterator
|
|
||||||
{
|
|
||||||
Eina_Iterator iterator;
|
|
||||||
|
|
||||||
DIR *dirp;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
char dir[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef HAVE_INOTIFY
|
#ifdef HAVE_INOTIFY
|
||||||
int ecore_file_monitor_inotify_init(void);
|
int ecore_file_monitor_inotify_init(void);
|
||||||
int ecore_file_monitor_inotify_shutdown(void);
|
int ecore_file_monitor_inotify_shutdown(void);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "eina_types.h"
|
#include "eina_types.h"
|
||||||
#include "eina_array.h"
|
#include "eina_array.h"
|
||||||
|
#include "eina_iterator.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup Eina_Tools_Group Tools
|
* @addtogroup Eina_Tools_Group Tools
|
||||||
|
@ -52,6 +53,7 @@ typedef void (*Eina_File_Dir_List_Cb)(const char *name, const char *path, void *
|
||||||
|
|
||||||
EAPI Eina_Bool eina_file_dir_list(const char *dir, Eina_Bool recursive, Eina_File_Dir_List_Cb cb, void *data) EINA_ARG_NONNULL(1, 3);
|
EAPI Eina_Bool eina_file_dir_list(const char *dir, Eina_Bool recursive, Eina_File_Dir_List_Cb cb, void *data) EINA_ARG_NONNULL(1, 3);
|
||||||
EAPI Eina_Array *eina_file_split(char *path) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
|
EAPI Eina_Array *eina_file_split(char *path) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
|
||||||
|
EAPI Eina_Iterator *eina_file_ls(const char *dir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|
|
@ -67,6 +67,59 @@ void *alloca (size_t);
|
||||||
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
||||||
#include "eina_safety_checks.h"
|
#include "eina_safety_checks.h"
|
||||||
#include "eina_file.h"
|
#include "eina_file.h"
|
||||||
|
#include "eina_stringshare.h"
|
||||||
|
|
||||||
|
typedef struct _Eina_File_Iterator Eina_File_Iterator;
|
||||||
|
struct _Eina_File_Iterator
|
||||||
|
{
|
||||||
|
Eina_Iterator iterator;
|
||||||
|
|
||||||
|
DIR *dirp;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
char dir[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
static Eina_Bool
|
||||||
|
_eina_file_ls_iterator_next(Eina_File_Iterator *it, void **data)
|
||||||
|
{
|
||||||
|
struct dirent *dp;
|
||||||
|
char *name;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
dp = readdir(it->dirp);
|
||||||
|
if (!dp) return EINA_FALSE;
|
||||||
|
}
|
||||||
|
while (!strcmp(dp->d_name, ".")
|
||||||
|
|| !strcmp(dp->d_name, ".."));
|
||||||
|
|
||||||
|
length = strlen(dp->d_name);
|
||||||
|
name = alloca(length + 2 + it->length);
|
||||||
|
|
||||||
|
memcpy(name, it->dir, it->length);
|
||||||
|
memcpy(name + it->length, "/", 1);
|
||||||
|
memcpy(name + it->length + 1, dp->d_name, length + 1);
|
||||||
|
|
||||||
|
*data = (char*) eina_stringshare_add(name);
|
||||||
|
return EINA_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
_eina_file_ls_iterator_container(Eina_File_Iterator *it)
|
||||||
|
{
|
||||||
|
return it->dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_eina_file_ls_iterator_free(Eina_File_Iterator *it)
|
||||||
|
{
|
||||||
|
closedir(it->dirp);
|
||||||
|
|
||||||
|
EINA_MAGIC_SET(&it->iterator, 0);
|
||||||
|
free(it);
|
||||||
|
}
|
||||||
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* Global *
|
* Global *
|
||||||
|
@ -268,6 +321,46 @@ eina_file_split(char *path)
|
||||||
return ea;
|
return ea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an iterator to list the content of a directory. Give a chance to interrupt it
|
||||||
|
* and make it completly asynchrone.
|
||||||
|
* The iterator will walk over '.' and '..' without returning them.
|
||||||
|
* @param dir The name of the directory to list
|
||||||
|
* @return Return an Eina_Iterator that will walk over the files and directory in the pointed
|
||||||
|
* directory. On failure it will return NULL.
|
||||||
|
*/
|
||||||
|
EAPI Eina_Iterator *
|
||||||
|
eina_file_ls(const char *dir)
|
||||||
|
{
|
||||||
|
Eina_File_Iterator *it;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
if (!dir) return NULL;
|
||||||
|
|
||||||
|
length = strlen(dir);
|
||||||
|
|
||||||
|
it = malloc(sizeof (Eina_File_Iterator) + length);
|
||||||
|
if (!it) return NULL;
|
||||||
|
|
||||||
|
EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_ITERATOR);
|
||||||
|
|
||||||
|
it->dirp = opendir(dir);
|
||||||
|
if (!it->dirp)
|
||||||
|
{
|
||||||
|
free(it);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(it->dir, dir, length + 1);
|
||||||
|
it->length = length;
|
||||||
|
|
||||||
|
it->iterator.next = FUNC_ITERATOR_NEXT(_eina_file_ls_iterator_next);
|
||||||
|
it->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(_eina_file_ls_iterator_container);
|
||||||
|
it->iterator.free = FUNC_ITERATOR_FREE(_eina_file_ls_iterator_free);
|
||||||
|
|
||||||
|
return &it->iterator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue