aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-02-26 16:57:21 +0100
committerBert <ber.t@gmx.com>2011-02-26 16:57:21 +0100
commitc5f6b2c0d5099b5ae94ff4412f5b181532e2d6a8 (patch)
treeeb41290101b531d0dec32ade50b606754b65f51e /main.c
parent5a35484e715d33763472ea473096a40b87ed126c (diff)
Sort directory entries when using -r
Diffstat (limited to 'main.c')
-rw-r--r--main.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/main.c b/main.c
index b5e99ec..a36e5a2 100644
--- a/main.c
+++ b/main.c
@@ -199,10 +199,15 @@ int check_append(const char *filename) {
}
}
+int fncmp(const void *a, const void *b) {
+ return strcoll(*((char* const*) a), *((char* const*) b));
+}
+
void read_dir_rec(const char *dirname) {
char *filename;
const char **dirnames;
int dircnt, diridx;
+ int fcnt, fstart;
unsigned char first;
size_t len;
DIR *dir;
@@ -217,6 +222,9 @@ void read_dir_rec(const char *dirname) {
dirnames = (const char**) s_malloc(dircnt * sizeof(const char*));
dirnames[0] = dirname;
+ fcnt = 0;
+ fstart = fileidx;
+
while (diridx > 0) {
dirname = dirnames[--diridx];
if (!(dir = opendir(dirname))) {
@@ -238,7 +246,9 @@ void read_dir_rec(const char *dirname) {
}
dirnames[diridx++] = filename;
} else {
- if (!check_append(filename))
+ if (check_append(filename))
+ ++fcnt;
+ else
free(filename);
}
}
@@ -251,6 +261,9 @@ void read_dir_rec(const char *dirname) {
first = 0;
}
+ if (fcnt > 1)
+ qsort(filenames + fstart, fcnt, sizeof(char*), fncmp);
+
free(dirnames);
}