mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 01:51:03 +09:00
LibCore: Expose file type from DirIterator
Our `find` utility makes use of the `dirent::d_type` field for filtering results, which `Core::DirIterator` didn't expose. So, now it does. :^) We now store the name and type of the entry as the "next" value instead of just the name. The type is exposed as a `DirectoryEntry::Type` instead of a `DT_FOO` constant, so that we're not tied to posixy systems, and because proper enums are nice. :^)
This commit is contained in:
parent
bc0bb98c01
commit
a98ae8f357
Notes:
sideshowbarker
2024-07-17 07:25:39 +09:00
Author: https://github.com/AtkinsSJ
Commit: a98ae8f357
Pull-request: https://github.com/SerenityOS/serenity/pull/17694
5 changed files with 106 additions and 14 deletions
45
Userland/Libraries/LibCore/DirectoryEntry.cpp
Normal file
45
Userland/Libraries/LibCore/DirectoryEntry.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "DirectoryEntry.h"
|
||||
#include <dirent.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
static DirectoryEntry::Type directory_entry_type_from_posix(unsigned char dt_constant)
|
||||
{
|
||||
switch (dt_constant) {
|
||||
case DT_UNKNOWN:
|
||||
return DirectoryEntry::Type::Unknown;
|
||||
case DT_FIFO:
|
||||
return DirectoryEntry::Type::NamedPipe;
|
||||
case DT_CHR:
|
||||
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;
|
||||
case DT_SOCK:
|
||||
return DirectoryEntry::Type::Socket;
|
||||
case DT_WHT:
|
||||
return DirectoryEntry::Type::Whiteout;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
DirectoryEntry DirectoryEntry::from_dirent(dirent const& de)
|
||||
{
|
||||
return DirectoryEntry {
|
||||
.type = directory_entry_type_from_posix(de.d_type),
|
||||
.name = de.d_name,
|
||||
};
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue