LibFileSystem: Add FileSystem::is_regular_file

This commit is contained in:
Shannon Booth 2023-07-07 00:29:31 +12:00 committed by Sam Atkins
commit b2d33c5689
Notes: sideshowbarker 2024-07-17 07:31:31 +09:00
2 changed files with 21 additions and 0 deletions

View file

@ -121,6 +121,24 @@ bool is_char_device(int fd)
return S_ISCHR(st.st_mode);
}
bool is_regular_file(StringView path)
{
auto st_or_error = Core::System::stat(path);
if (st_or_error.is_error())
return false;
auto st = st_or_error.release_value();
return S_ISREG(st.st_mode);
}
bool is_regular_file(int fd)
{
auto st_or_error = Core::System::fstat(fd);
if (st_or_error.is_error())
return false;
auto st = st_or_error.release_value();
return S_ISREG(st.st_mode);
}
bool is_directory(StringView path)
{
auto st_or_error = Core::System::stat(path);