summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Aguirre <aguirre.nicolas@gmail.com>2015-01-30 15:01:07 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-02-11 17:03:39 +0100
commit3b52489368837a46abf0cd4193043081256e03e8 (patch)
treefb9e4dfa8e89fb849534ed062fac0d260091145f
parent797c921f10eaaecdd7d6a61bec5955e4295e727e (diff)
downloadefl-3b52489368837a46abf0cd4193043081256e03e8.tar.gz
eina: fix directory listing on windows when directory is empty.
Using of INVALID_HANDLE_VALUE and ERROR_NO_MORE_FILES to handle this properlly. @fix
-rw-r--r--src/lib/eina/eina_file_win32.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/eina/eina_file_win32.c b/src/lib/eina/eina_file_win32.c
index 4398e0b384..9987fdfb4c 100644
--- a/src/lib/eina/eina_file_win32.c
+++ b/src/lib/eina/eina_file_win32.c
@@ -144,7 +144,7 @@ _eina_file_win32_first_file(const char *dir, WIN32_FIND_DATA *fd)
wdir = evil_char_to_wchar(dir);
if (!wdir)
- return NULL;
+ return INVALID_HANDLE_VALUE;
h = FindFirstFile(wdir, fd);
free(wdir);
@@ -153,14 +153,14 @@ _eina_file_win32_first_file(const char *dir, WIN32_FIND_DATA *fd)
#endif
if (!h)
- return NULL;
+ return INVALID_HANDLE_VALUE;
while ((fd->cFileName[0] == '.') &&
((fd->cFileName[1] == '\0') ||
((fd->cFileName[1] == '.') && (fd->cFileName[2] == '\0'))))
{
if (!FindNextFile(h, fd))
- return NULL;
+ return INVALID_HANDLE_VALUE;
}
return h;
@@ -181,7 +181,11 @@ _eina_file_win32_ls_iterator_next(Eina_File_Iterator *it, void **data)
Eina_Bool res = EINA_TRUE;
if (it->handle == INVALID_HANDLE_VALUE)
- return EINA_FALSE;
+ {
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ it->is_last = EINA_TRUE;
+ return EINA_FALSE;
+ }
is_last = it->is_last;
#ifdef UNICODE
@@ -263,7 +267,11 @@ _eina_file_win32_direct_ls_iterator_next(Eina_File_Direct_Iterator *it, void **d
Eina_Bool res = EINA_TRUE;
if (it->handle == INVALID_HANDLE_VALUE)
- return EINA_FALSE;
+ {
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ it->is_last = EINA_TRUE;
+ return EINA_FALSE;
+ }
attr = it->data.dwFileAttributes;
is_last = it->is_last;
@@ -580,7 +588,7 @@ eina_file_ls(const char *dir)
it->handle = _eina_file_win32_first_file(new_dir, &it->data);
free(new_dir);
- if (it->handle == INVALID_HANDLE_VALUE)
+ if ((it->handle == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_NO_MORE_FILES))
goto free_it;
memcpy(it->dir, dir, length + 1);
@@ -631,7 +639,7 @@ eina_file_direct_ls(const char *dir)
it->handle = _eina_file_win32_first_file(new_dir, &it->data);
free(new_dir);
- if (it->handle == INVALID_HANDLE_VALUE)
+ if ((it->handle == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_NO_MORE_FILES))
goto free_it;
memcpy(it->dir, dir, length + 1);