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:
parent
a505d3e494
commit
b6f6bb387c
@ -94,6 +94,13 @@ void FileLister::browse(const string& path, bool clean)
|
||||
}
|
||||
|
||||
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;
|
||||
struct stat 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));
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
isDir = S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
if (isDir) {
|
||||
if (!showDirectories)
|
||||
continue;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user