summaryrefslogtreecommitdiff
path: root/utils/filename.c
diff options
context:
space:
mode:
authorRob Kendrick <rjek@netsurf-browser.org>2007-06-10 11:11:46 +0000
committerRob Kendrick <rjek@netsurf-browser.org>2007-06-10 11:11:46 +0000
commit818a74417848213d30adf1a287557edee121b32f (patch)
tree1a1319fe5424769023bac81fc78a107856bb7dad /utils/filename.c
parentec40330a5b9b916b3d0ee039547d76a44133d926 (diff)
downloadnetsurf-818a74417848213d30adf1a287557edee121b32f.tar.gz
netsurf-818a74417848213d30adf1a287557edee121b32f.tar.bz2
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
Diffstat (limited to 'utils/filename.c')
-rw-r--r--utils/filename.c21
1 files changed, 15 insertions, 6 deletions
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 <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <sys/stat.h>
+#include <unistd.h>
#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;