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:
parent
4011a107a4
commit
6ea4be36b5
Notes:
sideshowbarker
2024-07-19 16:53:20 +09:00
Author: https://github.com/ghost
Commit: 6ea4be36b5
Pull-request: https://github.com/SerenityOS/serenity/pull/19384
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/Hendiadyoin1
3 changed files with 46 additions and 5 deletions
|
@ -56,7 +56,11 @@ bool DirIterator::advance_next()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AK_OS_SOLARIS
|
||||||
|
m_next = DirectoryEntry::from_stat(m_dir, *de);
|
||||||
|
#else
|
||||||
m_next = DirectoryEntry::from_dirent(*de);
|
m_next = DirectoryEntry::from_dirent(*de);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (m_next->name.is_empty())
|
if (m_next->name.is_empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -5,10 +5,34 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DirectoryEntry.h"
|
#include "DirectoryEntry.h"
|
||||||
#include <dirent.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace Core {
|
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)
|
static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_constant)
|
||||||
{
|
{
|
||||||
switch (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;
|
return DirectoryEntry::Type::SymbolicLink;
|
||||||
case DT_SOCK:
|
case DT_SOCK:
|
||||||
return DirectoryEntry::Type::Socket;
|
return DirectoryEntry::Type::Socket;
|
||||||
#ifndef AK_OS_OPENBSD
|
# ifndef AK_OS_OPENBSD
|
||||||
case DT_WHT:
|
case DT_WHT:
|
||||||
return DirectoryEntry::Type::Whiteout;
|
return DirectoryEntry::Type::Whiteout;
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
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)
|
DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
||||||
{
|
{
|
||||||
return DirectoryEntry {
|
return DirectoryEntry {
|
||||||
|
@ -43,5 +79,6 @@ DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
||||||
.name = de.d_name,
|
.name = de.d_name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/DeprecatedString.h>
|
||||||
|
#include <dirent.h>
|
||||||
struct dirent;
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
@ -29,6 +28,7 @@ struct DirectoryEntry {
|
||||||
DeprecatedString name;
|
DeprecatedString name;
|
||||||
|
|
||||||
static DirectoryEntry from_dirent(dirent const&);
|
static DirectoryEntry from_dirent(dirent const&);
|
||||||
|
static DirectoryEntry from_stat(DIR*, dirent const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue