mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Add File::is_{block,char}_device() helpers
The existing File::is_device() helpers don't distinguish between block and char devices. This commit adds File::is_block_device() and File::is_char_device() helpers which are more specific.
This commit is contained in:
parent
380ce43afc
commit
7b8088c78d
Notes:
sideshowbarker
2024-07-17 08:41:05 +09:00
Author: https://github.com/SamuelBowman Commit: https://github.com/SerenityOS/serenity/commit/7b8088c78d Pull-request: https://github.com/SerenityOS/serenity/pull/14432 Reviewed-by: https://github.com/linusg
2 changed files with 36 additions and 0 deletions
|
@ -115,6 +115,38 @@ bool File::is_device(String const& filename)
|
|||
return S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_block_device() const
|
||||
{
|
||||
struct stat stat;
|
||||
if (fstat(fd(), &stat) < 0)
|
||||
return false;
|
||||
return S_ISBLK(stat.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_block_device(String const& filename)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename.characters(), &st) < 0)
|
||||
return false;
|
||||
return S_ISBLK(st.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_char_device() const
|
||||
{
|
||||
struct stat stat;
|
||||
if (fstat(fd(), &stat) < 0)
|
||||
return false;
|
||||
return S_ISCHR(stat.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_char_device(String const& filename)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename.characters(), &st) < 0)
|
||||
return false;
|
||||
return S_ISCHR(st.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_directory() const
|
||||
{
|
||||
struct stat stat;
|
||||
|
|
|
@ -28,6 +28,10 @@ public:
|
|||
|
||||
bool is_device() const;
|
||||
static bool is_device(String const& filename);
|
||||
bool is_block_device() const;
|
||||
static bool is_block_device(String const& filename);
|
||||
bool is_char_device() const;
|
||||
static bool is_char_device(String const& filename);
|
||||
|
||||
bool is_link() const;
|
||||
static bool is_link(String const& filename);
|
||||
|
|
Loading…
Reference in a new issue