1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-25 16:17:10 +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 file = dptr->d_name;
string filepath = slashedPath + file; bool isDir;
struct stat st; #ifdef DT_DIR
int statRet = stat(filepath.c_str(), &st); if (dptr->d_type != DT_UNKNOWN) {
if (statRet == -1) { isDir = dptr->d_type == DT_DIR;
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno)); } else
continue; #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) if (!showDirectories)
continue; continue;