dtbtool: use stat to determine file type if its unknown

* Some filesystems (xfs) return 0 for d_type on readdir
* If the file type is unknown, attempt a stat call to see if
  it can be found that way.

Change-Id: I2f7a90a73cd9614aa34cd4654d007393f45db9f9
diff --git a/qcom/dtbtool/dtbtool.c b/qcom/dtbtool/dtbtool.c
index 20bc014..8867a2b 100644
--- a/qcom/dtbtool/dtbtool.c
+++ b/qcom/dtbtool/dtbtool.c
@@ -776,7 +776,19 @@
        extract "qcom,msm-id" parameter
      */
     while ((dp = readdir(dir)) != NULL) {
-        if ((dp->d_type == DT_REG)) {
+        if (dp->d_type == DT_UNKNOWN) {
+            struct stat statbuf;
+            char name[PATH_MAX];
+            snprintf(name, sizeof(name), "%s%s%s",
+                     input_dir,
+                     (input_dir[strlen(input_dir) - 1] == '/' ? "" : "/"),
+                     dp->d_name);
+            if (!stat(name, &statbuf) && S_ISREG(statbuf.st_mode)) {
+                dp->d_type = DT_REG;
+            }
+        }
+
+        if (dp->d_type == DT_REG) {
             flen = strlen(dp->d_name);
             if ((flen > 4) &&
                 (strncmp(&dp->d_name[flen-4], ".dtb", 4) == 0)) {