summaryrefslogtreecommitdiff
path: root/content/fetchers/file.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-11-11 11:38:48 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-11-11 11:38:48 +0000
commit7a920ace39937b7bc665ec7e3b716e6353467b00 (patch)
tree73e9b82e2ce7e649b5acc4a86db5d292124d5203 /content/fetchers/file.c
parent74d430f44ac949a8832ebeaa535d9321dc3f9456 (diff)
downloadnetsurf-7a920ace39937b7bc665ec7e3b716e6353467b00.tar.gz
netsurf-7a920ace39937b7bc665ec7e3b716e6353467b00.tar.bz2
Marginally cleaner handling of scandir absence.
Diffstat (limited to 'content/fetchers/file.c')
-rw-r--r--content/fetchers/file.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index f0c78ded2..7c87a905b 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -505,20 +505,18 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
char urlpath[PATH_MAX]; /* buffer for leaf entry path */
struct dirent *ent; /* current directroy entry */
-#if defined(_WIN32)
- /* Mingw lacks scandir and alphasort functions, so use opendir */
- DIR *scandir; /* handle for enumerating the directory */
-
- scandir = opendir(ctx->path);
- if (scandir == NULL) {
-#else
- /* Use scandir everywhere else */
+#ifdef HAVE_SCANDIR
struct dirent **listing = NULL; /* directory entry listing */
int i; /* directory entry index */
int n; /* number of directory entries */
n = scandir(ctx->path, &listing, 0, alphasort);
if (n < 0) {
+#else
+ DIR *scandir; /* handle for enumerating the directory */
+
+ scandir = opendir(ctx->path);
+ if (scandir == NULL) {
#endif
fetch_file_process_error(ctx,
fetch_file_errno_to_http_code(errno));
@@ -577,11 +575,11 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
if (fetch_file_send_callback(&msg, ctx))
goto fetch_file_process_dir_aborted;
-#if defined(_WIN32)
- while ((ent = readdir(scandir)) != NULL) {
-#else
+#ifdef HAVE_SCANDIR
for (i = 0; i < n; i++) {
ent = listing[i];
+#else
+ while ((ent = readdir(scandir)) != NULL) {
#endif
if (ent->d_name[0] == '.')
@@ -667,15 +665,15 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
fetch_file_process_dir_aborted:
-#if defined(_WIN32)
- closedir(scandir);
-#else
+#ifdef HAVE_SCANDIR
if (listing != NULL) {
for (i = 0; i < n; i++) {
free(listing[i]);
}
free(listing);
}
+#else
+ closedir(scandir);
#endif
}