mirror of
https://github.com/minetest/minetest.git
synced 2024-11-10 09:43:45 +01:00
Add support for unix filesystems which yield DT_UNKNOWN in dirent->d_type, falling back on stat().
This commit is contained in:
parent
bc5cc638fc
commit
ab67985d21
@ -190,9 +190,34 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
|
|||||||
if(dirp->d_name[0]!='.'){
|
if(dirp->d_name[0]!='.'){
|
||||||
DirListNode node;
|
DirListNode node;
|
||||||
node.name = dirp->d_name;
|
node.name = dirp->d_name;
|
||||||
if(dirp->d_type == DT_DIR) node.dir = true;
|
if(node.name == "." || node.name == "..")
|
||||||
else node.dir = false;
|
continue;
|
||||||
if(node.name != "." && node.name != "..")
|
|
||||||
|
int isdir = -1; // -1 means unknown
|
||||||
|
|
||||||
|
/*
|
||||||
|
POSIX doesn't define d_type member of
|
||||||
|
struct dirent and certain filesystems on
|
||||||
|
glibc/Linux will only return DT_UNKNOWN for
|
||||||
|
the d_type member.
|
||||||
|
*/
|
||||||
|
#ifdef _DIRENT_HAVE_D_TYPE
|
||||||
|
if(dirp->d_type != DT_UNKNOWN)
|
||||||
|
isdir = (dirp->d_type == DT_DIR);
|
||||||
|
#endif /* _DIRENT_HAVE_D_TYPE */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Was d_type DT_UNKNOWN (or nonexistent)?
|
||||||
|
If so, try stat().
|
||||||
|
*/
|
||||||
|
if(isdir == -1)
|
||||||
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
if (stat((pathstring + "/" + node.name).c_str(), &statbuf))
|
||||||
|
continue;
|
||||||
|
isdir = ((statbuf.st_mode & S_IFDIR) == S_IFDIR);
|
||||||
|
}
|
||||||
|
node.dir = isdir;
|
||||||
listing.push_back(node);
|
listing.push_back(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user