summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/fetchers/file.c26
-rw-r--r--utils/config.h5
2 files changed, 17 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
}
diff --git a/utils/config.h b/utils/config.h
index 1c1eef6c4..2503235b5 100644
--- a/utils/config.h
+++ b/utils/config.h
@@ -95,6 +95,11 @@ char *realpath(const char *path, char *resolved_path);
#undef HAVE_MMAP
#endif
+#define HAVE_SCANDIR
+#if (defined(_WIN32))
+#undef HAVE_SCANDIR
+#endif
+
/* This section toggles build options on and off.
* Simply undefine a symbol to turn the relevant feature off.
*