mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibCore: Add Core::File is_device() helpers
The helpers check if the file is a block device or a character device via stat and fstat.
This commit is contained in:
parent
4ee23752a5
commit
aff774c8ac
2 changed files with 19 additions and 0 deletions
|
@ -110,6 +110,22 @@ bool File::open_impl(IODevice::OpenMode mode, mode_t permissions)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool File::is_device() const
|
||||
{
|
||||
struct stat stat;
|
||||
if (fstat(fd(), &stat) < 0)
|
||||
return false;
|
||||
return S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_device(const String& filename)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename.characters(), &st) < 0)
|
||||
return false;
|
||||
return S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode);
|
||||
}
|
||||
|
||||
bool File::is_directory() const
|
||||
{
|
||||
struct stat stat;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue