timezone: If there is no d_type support use fstatat()
authorAndrei Gherzan <andrei@gherzan.ro>
Wed, 15 Aug 2012 19:38:51 +0000 (22:38 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 16 Aug 2012 11:58:35 +0000 (14:58 +0300)
This is useful for filesystems where d_type is always DT_UNKNOWN,
for example reiserfs, jffs2 and ubifs. In this case use the
fstatat() function.

src/timezone.c

index 173d658..141bad3 100644 (file)
@@ -157,6 +157,8 @@ static char *find_origin(void *src_map, struct stat *src_st,
        DIR *dir;
        struct dirent *d;
        char *str, pathname[PATH_MAX];
+       struct stat buf;
+       int ret;
 
        if (subpath == NULL)
                strncpy(pathname, basepath, sizeof(pathname));
@@ -192,6 +194,17 @@ static char *find_origin(void *src_map, struct stat *src_st,
                                return str;
                        }
                        break;
+               case DT_UNKNOWN:
+                       /*
+                        * If there is no d_type support use fstatat()
+                        * to check if d_name is directory
+                        * Let the code fall through
+                        */
+                       ret = fstatat(dirfd(dir), d->d_name, &buf, 0);
+                       if (ret < 0)
+                               continue;
+                       if ((buf.st_mode & S_IFDIR) == 0)
+                               continue;
                case DT_DIR:
                        if (subpath == NULL)
                                strncpy(pathname, d->d_name, sizeof(pathname));