mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibCore: Add fd overload of File::is_directory
and File::is_device
This commit is contained in:
parent
9ae97c8cb1
commit
cfb0e1bdb2
2 changed files with 20 additions and 8 deletions
|
@ -104,10 +104,7 @@ int File::leak_fd()
|
||||||
|
|
||||||
bool File::is_device() const
|
bool File::is_device() const
|
||||||
{
|
{
|
||||||
struct stat stat;
|
return is_device(fd());
|
||||||
if (fstat(fd(), &stat) < 0)
|
|
||||||
return false;
|
|
||||||
return S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::is_device(DeprecatedString const& filename)
|
bool File::is_device(DeprecatedString const& filename)
|
||||||
|
@ -118,6 +115,14 @@ bool File::is_device(DeprecatedString const& filename)
|
||||||
return S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode);
|
return S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::is_device(int fd)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) < 0)
|
||||||
|
return false;
|
||||||
|
return S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
bool File::is_block_device() const
|
bool File::is_block_device() const
|
||||||
{
|
{
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
@ -152,10 +157,7 @@ bool File::is_char_device(DeprecatedString const& filename)
|
||||||
|
|
||||||
bool File::is_directory() const
|
bool File::is_directory() const
|
||||||
{
|
{
|
||||||
struct stat stat;
|
return is_directory(fd());
|
||||||
if (fstat(fd(), &stat) < 0)
|
|
||||||
return false;
|
|
||||||
return S_ISDIR(stat.st_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::is_directory(DeprecatedString const& filename)
|
bool File::is_directory(DeprecatedString const& filename)
|
||||||
|
@ -166,6 +168,14 @@ bool File::is_directory(DeprecatedString const& filename)
|
||||||
return S_ISDIR(st.st_mode);
|
return S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::is_directory(int fd)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(fd, &st) < 0)
|
||||||
|
return false;
|
||||||
|
return S_ISDIR(st.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
bool File::is_link() const
|
bool File::is_link() const
|
||||||
{
|
{
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
|
|
@ -33,9 +33,11 @@ public:
|
||||||
|
|
||||||
bool is_directory() const;
|
bool is_directory() const;
|
||||||
static bool is_directory(DeprecatedString const& filename);
|
static bool is_directory(DeprecatedString const& filename);
|
||||||
|
static bool is_directory(int fd);
|
||||||
|
|
||||||
bool is_device() const;
|
bool is_device() const;
|
||||||
static bool is_device(DeprecatedString const& filename);
|
static bool is_device(DeprecatedString const& filename);
|
||||||
|
static bool is_device(int fd);
|
||||||
bool is_block_device() const;
|
bool is_block_device() const;
|
||||||
static bool is_block_device(DeprecatedString const& filename);
|
static bool is_block_device(DeprecatedString const& filename);
|
||||||
bool is_char_device() const;
|
bool is_char_device() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue