From 288b801e42f33d43a6c021a4a6e344498fb41ded Mon Sep 17 00:00:00 2001 From: Davide Andreoli Date: Sun, 22 Jun 2008 15:10:00 +0000 Subject: [PATCH] as per irc add the function: EAPI int ecore_file_dir_is_empty(const char*dir) Should we need to upgrade the ecore version? so apps that need this function can check for the right version? Thanks Dave SVN revision: 34889 --- legacy/ecore/src/lib/ecore_file/Ecore_File.h | 1 + legacy/ecore/src/lib/ecore_file/ecore_file.c | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/legacy/ecore/src/lib/ecore_file/Ecore_File.h b/legacy/ecore/src/lib/ecore_file/Ecore_File.h index d8dd3a1678..03c2355f22 100644 --- a/legacy/ecore/src/lib/ecore_file/Ecore_File.h +++ b/legacy/ecore/src/lib/ecore_file/Ecore_File.h @@ -88,6 +88,7 @@ extern "C" { EAPI char *ecore_file_app_exe_get (const char *app); EAPI char *ecore_file_escape_name (const char *filename); EAPI char *ecore_file_strip_ext (const char *file); + EAPI int ecore_file_dir_is_empty (const char *dir); EAPI Ecore_File_Monitor * ecore_file_monitor_add(const char *path, void (*func) (void *data, Ecore_File_Monitor *em, diff --git a/legacy/ecore/src/lib/ecore_file/ecore_file.c b/legacy/ecore/src/lib/ecore_file/ecore_file.c index e99ff63206..10b9d581d4 100644 --- a/legacy/ecore/src/lib/ecore_file/ecore_file.c +++ b/legacy/ecore/src/lib/ecore_file/ecore_file.c @@ -701,3 +701,30 @@ ecore_file_strip_ext(const char *path) return file; } + +/** + * Check if the given directory is empty. The '.' and '..' files will be ignored. + * @param dir The name of the directory to check + * @return 1 if directory is empty, 0 if it has at least one file or -1 in case of errors + */ +EAPI int +ecore_file_dir_is_empty(const char *dir) +{ + DIR *dirp; + struct dirent *dp; + + dirp = opendir(dir); + if (!dirp) return -1; + + while ((dp = readdir(dirp))) + { + if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, ".."))) + { + closedir(dirp); + return 0; + } + } + + closedir(dirp); + return 1; +}