mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 12:17:52 +00:00
LibCore: Port DirIterator to Windows using vcpkg dirent.h
This commit is contained in:
parent
cf198d0d60
commit
16ab3c5f9d
Notes:
github-actions[bot]
2024-11-05 17:43:44 +00:00
Author: https://github.com/stasoid
Commit: 16ab3c5f9d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1957
Reviewed-by: https://github.com/ADKaster ✅
6 changed files with 34 additions and 14 deletions
|
@ -21,6 +21,11 @@ endif()
|
|||
|
||||
serenity_lib(LibCoreMinimal coreminimal)
|
||||
|
||||
if (WIN32)
|
||||
find_path(DIRENT_INCLUDE_DIR dirent.h REQUIRED)
|
||||
target_include_directories(LibCoreMinimal PRIVATE ${DIRENT_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if (LAGOM_TOOLS_ONLY)
|
||||
return()
|
||||
endif()
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
@ -79,6 +78,7 @@ bool DirIterator::advance_next()
|
|||
if (m_flags & Flags::SkipParentAndBaseDir && (m_next->name == "." || m_next->name == ".."))
|
||||
continue;
|
||||
|
||||
#ifndef AK_OS_WINDOWS
|
||||
if constexpr (dirent_has_d_type) {
|
||||
// dirent structures from readdir aren't guaranteed to contain valid file types,
|
||||
// as it is possible that the underlying filesystem doesn't keep track of those.
|
||||
|
@ -94,6 +94,7 @@ bool DirIterator::advance_next()
|
|||
m_next->type = DirectoryEntry::directory_entry_type_from_stat(statbuf.st_mode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return !m_next->name.is_empty();
|
||||
}
|
||||
|
@ -135,11 +136,13 @@ ByteString DirIterator::next_full_path()
|
|||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
#ifndef AK_OS_WINDOWS
|
||||
int DirIterator::fd() const
|
||||
{
|
||||
if (!m_dir)
|
||||
return -1;
|
||||
return dirfd(m_dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteString.h>
|
||||
#include <LibCore/DirectoryEntry.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "DirectoryEntry.h"
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -68,14 +69,16 @@ DirectoryEntry::Type DirectoryEntry::directory_entry_type_from_stat(mode_t st_mo
|
|||
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;
|
||||
#ifndef AK_OS_WINDOWS
|
||||
case S_IFBLK:
|
||||
return DirectoryEntry::Type::BlockDevice;
|
||||
case S_IFSOCK:
|
||||
return DirectoryEntry::Type::Socket;
|
||||
#endif
|
||||
default:
|
||||
return DirectoryEntry::Type::Unknown;
|
||||
}
|
||||
|
@ -83,7 +86,7 @@ DirectoryEntry::Type DirectoryEntry::directory_entry_type_from_stat(mode_t st_mo
|
|||
}
|
||||
|
||||
#if !defined(AK_OS_SOLARIS) && !defined(AK_OS_HAIKU)
|
||||
static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_constant)
|
||||
static DirectoryEntry::Type directory_entry_type_from_posix(int dt_constant)
|
||||
{
|
||||
switch (dt_constant) {
|
||||
case DT_UNKNOWN:
|
||||
|
@ -94,15 +97,17 @@ static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_con
|
|||
return DirectoryEntry::Type::CharacterDevice;
|
||||
case DT_DIR:
|
||||
return DirectoryEntry::Type::Directory;
|
||||
case DT_BLK:
|
||||
return DirectoryEntry::Type::BlockDevice;
|
||||
case DT_REG:
|
||||
return DirectoryEntry::Type::File;
|
||||
case DT_LNK:
|
||||
return DirectoryEntry::Type::SymbolicLink;
|
||||
# ifndef AK_OS_WINDOWS
|
||||
case DT_BLK:
|
||||
return DirectoryEntry::Type::BlockDevice;
|
||||
case DT_SOCK:
|
||||
return DirectoryEntry::Type::Socket;
|
||||
# ifndef AK_OS_OPENBSD
|
||||
# endif
|
||||
# if !defined AK_OS_OPENBSD && !defined AK_OS_WINDOWS
|
||||
case DT_WHT:
|
||||
return DirectoryEntry::Type::Whiteout;
|
||||
# endif
|
||||
|
@ -111,6 +116,7 @@ static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_con
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef AK_OS_WINDOWS
|
||||
DirectoryEntry DirectoryEntry::from_stat(DIR* d, dirent const& de)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
@ -121,6 +127,7 @@ DirectoryEntry DirectoryEntry::from_stat(DIR* d, dirent const& de)
|
|||
.inode_number = de.d_ino,
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(AK_OS_SOLARIS) && !defined(AK_OS_HAIKU)
|
||||
DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
||||
|
@ -128,7 +135,7 @@ DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
|||
return DirectoryEntry {
|
||||
.type = directory_entry_type_from_posix(de.d_type),
|
||||
.name = de.d_name,
|
||||
.inode_number = de.d_ino,
|
||||
.inode_number = (ino_t)de.d_ino,
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -7,8 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/StringView.h>
|
||||
#ifdef AK_OS_WINDOWS
|
||||
struct dirent;
|
||||
struct DIR;
|
||||
#else
|
||||
# include <dirent.h>
|
||||
#endif
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
"http2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "dirent",
|
||||
"platform": "windows"
|
||||
},
|
||||
{
|
||||
"name": "fontconfig",
|
||||
"platform": "linux | freebsd | openbsd | osx | windows"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue