1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-27 07:13:20 +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,14 +94,24 @@ void FileLister::browse(const string& path, bool clean)
}
string file = dptr->d_name;
string filepath = slashedPath + file;
struct stat st;
int statRet = stat(filepath.c_str(), &st);
if (statRet == -1) {
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
continue;
bool isDir;
#ifdef DT_DIR
if (dptr->d_type != DT_UNKNOWN) {
isDir = dptr->d_type == DT_DIR;
} else
#endif
{
string filepath = slashedPath + file;
struct stat st;
int statRet = stat(filepath.c_str(), &st);
if (statRet == -1) {
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
continue;
}
isDir = S_ISDIR(st.st_mode);
}
if (S_ISDIR(st.st_mode)) {
if (isDir) {
if (!showDirectories)
continue;