From 818a74417848213d30adf1a287557edee121b32f Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 10 Jun 2007 11:11:46 +0000 Subject: Stop filename.c using d_type member in dirent struct, as this is completely and utterly unportable. Not even Linux has it anymore. svn path=/trunk/netsurf/; revision=3317 --- utils/filename.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/filename.c b/utils/filename.c index 85e0db4ab..52caa1e41 100644 --- a/utils/filename.c +++ b/utils/filename.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include "utils/filename.h" #include "utils/log.h" #include "utils/url.h" @@ -216,15 +218,20 @@ bool filename_flush_directory(const char *folder, int depth) { parent = opendir(folder); while ((entry = readdir(parent))) { + struct stat statbuf; + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; + snprintf(child, 256, "%s/%s", folder, entry->d_name); + stat(child, &statbuf); + /* first 3 depths are directories only, then files only */ if (depth < 3) - del = (entry->d_type != DT_DIR); + del = !S_ISDIR(statbuf.st_mode); else - del = (entry->d_type == DT_DIR); + del = S_ISDIR(statbuf.st_mode); /* check we are a file numbered '00' -> '63' */ if ((!del) && (entry->d_name[0] >= '0') && @@ -261,13 +268,13 @@ bool filename_flush_directory(const char *folder, int depth) { del = true; } /* continue if we are a valid reference so far */ - if ((!del) && (entry->d_type != DT_DIR)) - continue; + if ((!del) && (!S_ISDIR(statbuf.st_mode))) + continue; /* delete or recurse */ snprintf(child, 256, "%s/%s", folder, entry->d_name); child[255] = '\0'; if (del) { - if (entry->d_type == DT_DIR) + if (S_ISDIR(statbuf.st_mode)) filename_delete_recursive(child); if (remove(child)) LOG(("Failed to remove '%s'", child)); @@ -293,6 +300,7 @@ bool filename_delete_recursive(char *folder) { DIR *parent; struct dirent *entry; char child[256]; + struct stat statbuf; parent = opendir(folder); @@ -301,7 +309,8 @@ bool filename_delete_recursive(char *folder) { (!strcmp(entry->d_name, ".."))) continue; snprintf(child, 256, "%s/%s", folder, entry->d_name); - if (entry->d_type == DT_DIR) { + stat(child, &statbuf); + if (S_ISDIR(statbuf.st_mode)) { if (!filename_delete_recursive(child)) { closedir(parent); return false; -- cgit v1.2.3