mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
LibCore: Add methods to convert DirectoryEntry types to names
We can either convert DirectoryEntry::type to its representative name or to the POSIX DT_* name.
This commit is contained in:
parent
90152dc859
commit
d568b09632
2 changed files with 53 additions and 0 deletions
|
@ -9,6 +9,56 @@
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
StringView DirectoryEntry::posix_name_from_directory_entry_type(Type type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case Type::BlockDevice:
|
||||||
|
return "DT_BLK"sv;
|
||||||
|
case Type::CharacterDevice:
|
||||||
|
return "DT_CHR"sv;
|
||||||
|
case Type::Directory:
|
||||||
|
return "DT_DIR"sv;
|
||||||
|
case Type::File:
|
||||||
|
return "DT_REG"sv;
|
||||||
|
case Type::NamedPipe:
|
||||||
|
return "DT_FIFO"sv;
|
||||||
|
case Type::Socket:
|
||||||
|
return "DT_SOCK"sv;
|
||||||
|
case Type::SymbolicLink:
|
||||||
|
return "DT_LNK"sv;
|
||||||
|
case Type::Unknown:
|
||||||
|
return "DT_UNKNOWN"sv;
|
||||||
|
case Type::Whiteout:
|
||||||
|
return "DT_WHT"sv;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView DirectoryEntry::representative_name_from_directory_entry_type(Type type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case Type::BlockDevice:
|
||||||
|
return "BlockDevice"sv;
|
||||||
|
case Type::CharacterDevice:
|
||||||
|
return "CharacterDevice"sv;
|
||||||
|
case Type::Directory:
|
||||||
|
return "Directory"sv;
|
||||||
|
case Type::File:
|
||||||
|
return "File"sv;
|
||||||
|
case Type::NamedPipe:
|
||||||
|
return "NamedPipe"sv;
|
||||||
|
case Type::Socket:
|
||||||
|
return "Socket"sv;
|
||||||
|
case Type::SymbolicLink:
|
||||||
|
return "SymbolicLink"sv;
|
||||||
|
case Type::Unknown:
|
||||||
|
return "Unknown"sv;
|
||||||
|
case Type::Whiteout:
|
||||||
|
return "Whiteout"sv;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
DirectoryEntry::Type DirectoryEntry::directory_entry_type_from_stat(mode_t st_mode)
|
DirectoryEntry::Type DirectoryEntry::directory_entry_type_from_stat(mode_t st_mode)
|
||||||
{
|
{
|
||||||
switch (st_mode & S_IFMT) {
|
switch (st_mode & S_IFMT) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteString.h>
|
#include <AK/ByteString.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
@ -28,6 +29,8 @@ struct DirectoryEntry {
|
||||||
ByteString name;
|
ByteString name;
|
||||||
ino_t inode_number;
|
ino_t inode_number;
|
||||||
|
|
||||||
|
static StringView posix_name_from_directory_entry_type(Type);
|
||||||
|
static StringView representative_name_from_directory_entry_type(Type);
|
||||||
static Type directory_entry_type_from_stat(mode_t st_mode);
|
static Type directory_entry_type_from_stat(mode_t st_mode);
|
||||||
static DirectoryEntry from_dirent(dirent const&);
|
static DirectoryEntry from_dirent(dirent const&);
|
||||||
static DirectoryEntry from_stat(DIR*, dirent const&);
|
static DirectoryEntry from_stat(DIR*, dirent const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue