1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibCore: Fallback to fstat() on systems without d_type support

This commit is contained in:
Niklas Poslovski 2023-06-16 16:34:42 +02:00 committed by Sam Atkins
parent 4011a107a4
commit 6ea4be36b5
Notes: sideshowbarker 2024-07-19 16:53:20 +09:00
3 changed files with 46 additions and 5 deletions

View file

@ -56,7 +56,11 @@ bool DirIterator::advance_next()
return false;
}
#ifdef AK_OS_SOLARIS
m_next = DirectoryEntry::from_stat(m_dir, *de);
#else
m_next = DirectoryEntry::from_dirent(*de);
#endif
if (m_next->name.is_empty())
return false;

View file

@ -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) {
@ -35,7 +59,19 @@ static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_con
}
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
}

View file

@ -7,8 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
struct dirent;
#include <dirent.h>
namespace Core {
@ -29,6 +28,7 @@ struct DirectoryEntry {
DeprecatedString name;
static DirectoryEntry from_dirent(dirent const&);
static DirectoryEntry from_stat(DIR*, dirent const&);
};
}