diff --git a/Userland/Libraries/LibCore/DirIterator.cpp b/Userland/Libraries/LibCore/DirIterator.cpp index 0eefc9311e..4bce035cc9 100644 --- a/Userland/Libraries/LibCore/DirIterator.cpp +++ b/Userland/Libraries/LibCore/DirIterator.cpp @@ -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; diff --git a/Userland/Libraries/LibCore/DirectoryEntry.cpp b/Userland/Libraries/LibCore/DirectoryEntry.cpp index 4a3f762ef1..dfc16da66d 100644 --- a/Userland/Libraries/LibCore/DirectoryEntry.cpp +++ b/Userland/Libraries/LibCore/DirectoryEntry.cpp @@ -5,10 +5,34 @@ */ #include "DirectoryEntry.h" -#include +#include 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 } diff --git a/Userland/Libraries/LibCore/DirectoryEntry.h b/Userland/Libraries/LibCore/DirectoryEntry.h index 266c79bf0d..97ce7fe13b 100644 --- a/Userland/Libraries/LibCore/DirectoryEntry.h +++ b/Userland/Libraries/LibCore/DirectoryEntry.h @@ -7,8 +7,7 @@ #pragma once #include - -struct dirent; +#include namespace Core { @@ -29,6 +28,7 @@ struct DirectoryEntry { DeprecatedString name; static DirectoryEntry from_dirent(dirent const&); + static DirectoryEntry from_stat(DIR*, dirent const&); }; }