summaryrefslogtreecommitdiffstats
path: root/src/dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-04-27 18:15:43 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-04-27 18:15:43 +0200
commit8a6a397eb279ae4ee7b811c1ac97c91d3b911c32 (patch)
treefac5dd33f10c84f4687a1548ea14751dd46ce606 /src/dir.c
parenta3d8937a1918db7ac21968f0729c54f582eec711 (diff)
filesort(): better handle . and .. directory entries
Diffstat (limited to 'src/dir.c')
-rw-r--r--src/dir.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/dir.c b/src/dir.c
index 00e1e9c..a4b9630 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -342,8 +342,13 @@ int filesort(const struct td_list_head *a, const struct td_list_head *b)
if((file_a->st_mode&LINUX_S_IFDIR) && strcmp(file_a->name, ".")==0)
return -1;
if((file_a->st_mode&LINUX_S_IFDIR) && strcmp(file_a->name, "..")==0 &&
- !strcmp(file_b->name, ".")==0)
+ strcmp(file_b->name, ".")!=0)
return -1;
+ if((file_b->st_mode&LINUX_S_IFDIR) && strcmp(file_b->name, ".")==0)
+ return 1;
+ if((file_b->st_mode&LINUX_S_IFDIR) && strcmp(file_b->name, "..")==0 &&
+ strcmp(file_a->name, ".")!=0)
+ return 1;
/* Files and directories are sorted by name */
return strcmp(file_a->name, file_b->name);
}