From 0306bb5dafc7956a36430a83fb6cd6ca85f9253a Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Tue, 11 Dec 2007 22:41:18 +0100 Subject: [PATCH] Redefine readdir() on IsoFileSource, to skip "." and ".." dirs. --- src/fs_local.c | 18 ++++++++++++------ src/fsource.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/fs_local.c b/src/fs_local.c index e6672b7..738c9bc 100644 --- a/src/fs_local.c +++ b/src/fs_local.c @@ -281,12 +281,18 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child) size_t a, b; int ret; - entry = readdir(data->info.dir); - if (entry == NULL) { - if (errno == EBADF) - return ISO_FILE_ERROR; - else - return 0; /* EOF */ + /* while to skip "." and ".." dirs */ + while (1) { + entry = readdir(data->info.dir); + if (entry == NULL) { + if (errno == EBADF) + return ISO_FILE_ERROR; + else + return 0; /* EOF */ + } + if (strcmp(entry->d_name,".") && strcmp(entry->d_name,"..")) { + break; + } } /* constructs the new path */ diff --git a/src/fsource.h b/src/fsource.h index a8973a7..ef533f3 100644 --- a/src/fsource.h +++ b/src/fsource.h @@ -153,6 +153,8 @@ struct Iso_File_Source * The dir must be open() before calling this, and close() when no more * needed. Only valid for dirs. * + * Note that "." and ".." children MUST NOT BE returned. + * * @param child * pointer to be filled with the given child. Undefined on error or OEF * @return