1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 22:40:39 +02:00

Skip stat() call when the d_type field can tell us the file type

This is a BSD extension also present in glibc and uClibc. Not all libc
implementations and not all file systems support it, so we keep the
stat-based code as a fallback.
This commit is contained in:
Maarten ter Huurne 2014-08-14 05:25:26 +02:00
parent a505d3e494
commit b6f6bb387c

View File

@ -94,6 +94,13 @@ void FileLister::browse(const string& path, bool clean)
} }
string file = dptr->d_name; string file = dptr->d_name;
bool isDir;
#ifdef DT_DIR
if (dptr->d_type != DT_UNKNOWN) {
isDir = dptr->d_type == DT_DIR;
} else
#endif
{
string filepath = slashedPath + file; string filepath = slashedPath + file;
struct stat st; struct stat st;
int statRet = stat(filepath.c_str(), &st); int statRet = stat(filepath.c_str(), &st);
@ -101,7 +108,10 @@ void FileLister::browse(const string& path, bool clean)
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno)); ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
continue; continue;
} }
if (S_ISDIR(st.st_mode)) { isDir = S_ISDIR(st.st_mode);
}
if (isDir) {
if (!showDirectories) if (!showDirectories)
continue; continue;