summaryrefslogtreecommitdiff
path: root/src/file.c
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2004-04-07 18:47:00 +0000
committerStef Walter <stef@thewalter.net>2004-04-07 18:47:00 +0000
commitbf2dfe574ae38c5acea28648c379effad44aa970 (patch)
tree555ccc6056e457bd44693f284d02d06541cde822 /src/file.c
parent08c1eaa8aa0e6928bb5067df417ac785c1bce326 (diff)
Folder emuration fixes.
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/file.c b/src/file.c
index 4f42a5d..27db720 100644
--- a/src/file.c
+++ b/src/file.c
@@ -27,6 +27,12 @@
#if HAVE_UNISTD_H && HAVE_DIRENT_H
+int is_dots(struct dirent* entry)
+{
+ return entry->d_name &&
+ (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."));
+}
+
int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
{
struct dirent* ent = 0;
@@ -52,9 +58,10 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
}
}
#ifdef HAVE_FNMATCH
- while(0);
+ while(is_dots(ent));
#else
- while(fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH);
+ while(is_dots(ent) ||
+ fnmatch(wildcard, ent->d_name, FNM_PATHNAME) == FNM_NOMATCH);
#endif
if(ent)
@@ -90,6 +97,12 @@ void dir_close(DIR* handle)
#include <direct.h>
#include <io.h>
+int is_dots(struct _finddata_t* findinfo)
+{
+ return findinfo->name &&
+ (!strcmp(findinfo->name, ".") || !strcmp(findinfo->name, ".."));
+}
+
static void copyDirStruct(struct _finddata_t* findinfo, struct dirent* entry)
{
/* Copy the structure */
@@ -139,6 +152,18 @@ DIR* dir_first(const char* folder, const char* wildcard, struct dirent* entry)
free(handle);
return INVALID_DIR;
}
+
+ /* We don't do dots */
+ else if(is_dots(&findinfo))
+ {
+ if(dir_next(handle, wildcard, entry))
+ return handle;
+
+ errno = ENOENT;
+ return INVALID_DIR;
+ }
+
+ /* Copy the first file */
else
{
copyDirStruct(&findinfo, entry);
@@ -151,7 +176,12 @@ int dir_next(DIR* handle, const char* wildcard, struct dirent* entry)
struct _finddata_t findinfo;
int ret = _findnext(*handle, &findinfo) == 0;
if(ret)
- copyDirStruct(&findinfo, entry);
+ {
+ if(is_dots(&findinfo))
+ return dir_next(handle, wildcard, entry);
+ else
+ copyDirStruct(&findinfo, entry);
+ }
return ret;
}