From 7a920ace39937b7bc665ec7e3b716e6353467b00 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 11 Nov 2013 11:38:48 +0000 Subject: Marginally cleaner handling of scandir absence. --- content/fetchers/file.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'content/fetchers') 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 } -- cgit v1.2.3