shithub: choc

Download patch

ref: 35c999fa8678d6c9c03d97e34a378b466958c97a
parent: 67d4033dabed2e864944c8359b8cff1e66339143
author: Fabian Greffrath <fabian@greffrath.com>
date: Mon Oct 29 07:14:34 EDT 2018

glob: handle file systems returning DT_UNKNOWN for d_type (e.g. XFS)

While at it, also handle the symbolic links and simplify the previous
implementation by having only one function definition.

--- a/src/i_glob.c
+++ b/src/i_glob.c
@@ -36,38 +36,40 @@
 
 #ifndef NO_DIRENT_IMPLEMENTATION
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 // Only the fields d_name and (as an XSI extension) d_ino are specified
 // in POSIX.1.  Other than Linux, the d_type field is available mainly
 // only on BSD systems.  The remaining fields are available on many, but
 // not all systems.
-#if defined(_DIRENT_HAVE_D_TYPE)
 static boolean IsDirectory(char *dir, struct dirent *de)
 {
-    return de->d_type == DT_DIR;
-}
-#else
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+#if defined(_DIRENT_HAVE_D_TYPE)
+    if (de->d_type != DT_UNKNOWN && de->d_type != DT_LNK)
+    {
+        return de->d_type == DT_DIR;
+    }
+    else
+#endif
+    {
+        char *filename;
+        struct stat sb;
+        int result;
 
-static boolean IsDirectory(char *dir, struct dirent *de)
-{
-    char *filename;
-    struct stat sb;
-    int result;
+        filename = M_StringJoin(dir, DIR_SEPARATOR_S, de->d_name, NULL);
+        result = stat(filename, &sb);
+        free(filename);
 
-    filename = M_StringJoin(dir, DIR_SEPARATOR_S, de->d_name, NULL);
-    result = stat(filename, &sb);
-    free(filename);
+        if (result != 0)
+        {
+            return false;
+        }
 
-    if (result != 0)
-    {
-        return false;
+        return S_ISDIR(sb.st_mode);
     }
-
-    return S_ISDIR(sb.st_mode);
 }
-#endif
 
 struct glob_s
 {