summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-11-10 22:02:12 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-11-10 22:02:12 +0000
commit8a72d5be849f79c065a81a349a12b49c7e23dd03 (patch)
tree2c873bfb60f73293cf4ccb8f81c9bfd06050f591
parent5adb1fb1ddbc7adc1a84736c9a1a434d0bf1c0b0 (diff)
downloadnetsurf-8a72d5be849f79c065a81a349a12b49c7e23dd03.tar.gz
netsurf-8a72d5be849f79c065a81a349a12b49c7e23dd03.tar.bz2
Sort directory contents.
-rw-r--r--content/fetchers/file.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 21cee79d5..4585f1710 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -499,15 +499,17 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
nsurl *up; /* url of parent */
char *path; /* url for list entries */
- DIR *scandir; /* handle for enumerating the directory */
- struct dirent* ent; /* leaf directory entry */
+ struct dirent **listing = NULL; /* directory entry listing */
+ struct dirent *ent; /* current directroy entry */
struct stat ent_stat; /* stat result of leaf entry */
char datebuf[64]; /* buffer for date text */
char timebuf[64]; /* buffer for time text */
char urlpath[PATH_MAX]; /* buffer for leaf entry path */
+ int i; /* directory entry index */
+ int n; /* number of directory entries */
- scandir = opendir(ctx->path);
- if (scandir == NULL) {
+ n = scandir(ctx->path, &listing, 0, alphasort);
+ if (n < 0) {
fetch_file_process_error(ctx,
fetch_file_errno_to_http_code(errno));
return;
@@ -565,7 +567,8 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
if (fetch_file_send_callback(&msg, ctx))
goto fetch_file_process_dir_aborted;
- while ((ent = readdir(scandir)) != NULL) {
+ for (i = 0; i < n; i++) {
+ ent = listing[i];
if (ent->d_name[0] == '.')
continue;
@@ -650,7 +653,12 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
fetch_file_process_dir_aborted:
- closedir(scandir);
+ if (listing != NULL) {
+ for (i = 0; i < n; i++) {
+ free(listing[i]);
+ }
+ free(listing);
+ }
}