aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-07-07 02:45:30 -0700
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2014-12-21 23:38:02 +0800
commitb9db5553430d8355bab48275727f685c7c42fa66 (patch)
tree3ce7304c18eb199d7b586ec802fb6e8823466346
parent9b43e6fa8b9ab11826370ca6e4c6fa2aac3b486a (diff)
Support for dirents without d_type (e.g. Solaris)
-rw-r--r--wutil.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/wutil.cpp b/wutil.cpp
index 90313198..0c877f36 100644
--- a/wutil.cpp
+++ b/wutil.cpp
@@ -77,14 +77,32 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou
if (out_is_dir)
{
/* The caller cares if this is a directory, so check */
- bool is_dir;
+ bool is_dir = false;
+
+ /* We may be able to skip stat, if the readdir can tell us the file type directly */
+ bool check_with_stat = true;
+#if defined(_DIRENT_HAVE_D_TYPE) || __APPLE__
if (d->d_type == DT_DIR)
{
+ /* Known directory */
is_dir = true;
+ check_with_stat = false;
}
else if (d->d_type == DT_LNK || d->d_type == DT_UNKNOWN)
{
/* We want to treat symlinks to directories as directories. Use stat to resolve it. */
+ check_with_stat = true;
+ }
+ else
+ {
+ /* Regular file */
+ is_dir = false;
+ check_with_stat = false;
+ }
+#endif
+ if (check_with_stat)
+ {
+ /* We couldn't determine the file type from the dirent; check by stat'ing it */
cstring fullpath = wcs2string(dir_path);
fullpath.push_back('/');
fullpath.append(d->d_name);
@@ -98,10 +116,6 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou
is_dir = !!(S_ISDIR(buf.st_mode));
}
}
- else
- {
- is_dir = false;
- }
*out_is_dir = is_dir;
}
return true;