From 9dada2fefdb426c6551343a61ca084a22b0d6a1c Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Wed, 15 Aug 2012 22:38:51 +0300 Subject: [PATCH] timezone: If there is no d_type support use fstatat() 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/timezone.c b/src/timezone.c index 173d658a..141bad34 100644 --- a/src/timezone.c +++ b/src/timezone.c @@ -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)); -- 2.34.1