mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibCore: Fallback to fstat() on systems without d_type support
This commit is contained in:
parent
4011a107a4
commit
6ea4be36b5
3 changed files with 46 additions and 5 deletions
|
@ -5,10 +5,34 @@
|
|||
*/
|
||||
|
||||
#include "DirectoryEntry.h"
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
static DirectoryEntry::Type directory_entry_type_from_stat(mode_t st_mode)
|
||||
{
|
||||
switch (st_mode) {
|
||||
case S_IFIFO:
|
||||
return DirectoryEntry::Type::NamedPipe;
|
||||
case S_IFCHR:
|
||||
return DirectoryEntry::Type::CharacterDevice;
|
||||
case S_IFDIR:
|
||||
return DirectoryEntry::Type::Directory;
|
||||
case S_IFBLK:
|
||||
return DirectoryEntry::Type::BlockDevice;
|
||||
case S_IFREG:
|
||||
return DirectoryEntry::Type::File;
|
||||
case S_IFLNK:
|
||||
return DirectoryEntry::Type::SymbolicLink;
|
||||
case S_IFSOCK:
|
||||
return DirectoryEntry::Type::Socket;
|
||||
default:
|
||||
return DirectoryEntry::Type::Unknown;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
#ifndef AK_OS_SOLARIS
|
||||
static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_constant)
|
||||
{
|
||||
switch (dt_constant) {
|
||||
|
@ -28,14 +52,26 @@ static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_con
|
|||
return DirectoryEntry::Type::SymbolicLink;
|
||||
case DT_SOCK:
|
||||
return DirectoryEntry::Type::Socket;
|
||||
#ifndef AK_OS_OPENBSD
|
||||
# ifndef AK_OS_OPENBSD
|
||||
case DT_WHT:
|
||||
return DirectoryEntry::Type::Whiteout;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
#endif
|
||||
|
||||
DirectoryEntry DirectoryEntry::from_stat(DIR* d, dirent const& de)
|
||||
{
|
||||
struct stat statbuf;
|
||||
fstat(dirfd(d), &statbuf);
|
||||
return DirectoryEntry {
|
||||
.type = directory_entry_type_from_stat(statbuf.st_mode),
|
||||
.name = de.d_name,
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef AK_OS_SOLARIS
|
||||
DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
||||
{
|
||||
return DirectoryEntry {
|
||||
|
@ -43,5 +79,6 @@ DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
|||
.name = de.d_name,
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue