From 6bcd1197e1f9314cde1f8126b83dbe65cb912e6f Mon Sep 17 00:00:00 2001 From: Bartosz Szreder Date: Mon, 25 Jun 2018 16:19:09 +0200 Subject: [PATCH 1/2] Fix find_files for particular filesystems on linux. The current implementation uses readdir() and struct dirent->d_type field for determining whether we're dealing with a file or a directory. The manual states that the d_type field is not supported by all filesystem types. Therefore, whenever a d_type == DT_UNKNOWN is reported, fallback to using the fstatat() system call. --- crnlib/crn_find_files.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crnlib/crn_find_files.cpp b/crnlib/crn_find_files.cpp index 1c3f7fd5..1ae097ad 100644 --- a/crnlib/crn_find_files.cpp +++ b/crnlib/crn_find_files.cpp @@ -9,8 +9,12 @@ #include "crn_winhdr.h" #elif defined(__GNUC__) +#include #include #include +#include +#include +#include #endif namespace crnlib { @@ -195,6 +199,8 @@ bool find_files::find_internal(const char* pBasepath, const char* pRelpath, cons if (!dp) return level ? true : false; + const int dirDesc = dirfd(dp); + dynamic_string_array paths; for (;;) { @@ -204,8 +210,25 @@ bool find_files::find_internal(const char* pBasepath, const char* pRelpath, cons if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) continue; - const bool is_directory = (ep->d_type & DT_DIR) != 0; - const bool is_file = (ep->d_type & DT_REG) != 0; + bool is_directory = false, is_file = false; + + if (ep->d_type != DT_UNKNOWN) + { + is_directory = (ep->d_type & DT_DIR) != 0; + is_file = (ep->d_type & DT_REG) != 0; + } + else + { + struct stat st; + if (fstatat(dirDesc, ep->d_name, &st, AT_SYMLINK_NOFOLLOW) == 0) + { + is_directory = (st.st_mode & S_IFDIR) != 0; + is_file = (st.st_mode & S_IFREG) != 0; + } + } + + if (!is_directory && !is_file) + continue; dynamic_string filename(ep->d_name); From 5bafd600767da0c4be834634033e5f659b48e109 Mon Sep 17 00:00:00 2001 From: Bartosz Szreder Date: Mon, 25 Jun 2018 16:30:02 +0200 Subject: [PATCH 2/2] Remove stale references to crn_zeng.* files. --- crnlib/Makefile | 1 - crnlib/crnlib.cbp | 2 -- crnlib/crnlib_linux.cbp | 2 -- 3 files changed, 5 deletions(-) diff --git a/crnlib/Makefile b/crnlib/Makefile index 9a9de187..8d2dfcec 100644 --- a/crnlib/Makefile +++ b/crnlib/Makefile @@ -51,7 +51,6 @@ OBJECTS = \ crn_utils.o \ crn_value.o \ crn_vector.o \ - crn_zeng.o \ crn_texture_comp.o \ crn_texture_conversion.o \ crn_dds_comp.o \ diff --git a/crnlib/crnlib.cbp b/crnlib/crnlib.cbp index fe9354e1..aeb67e49 100644 --- a/crnlib/crnlib.cbp +++ b/crnlib/crnlib.cbp @@ -189,8 +189,6 @@ - - diff --git a/crnlib/crnlib_linux.cbp b/crnlib/crnlib_linux.cbp index 2b68e926..bfe30306 100644 --- a/crnlib/crnlib_linux.cbp +++ b/crnlib/crnlib_linux.cbp @@ -189,8 +189,6 @@ - -