mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
LibCore: Implement File::is_link()
It was already possible to check if a path was a directory or a device. Now, it is possible to check if a path is a link in a similar manner.
This commit is contained in:
parent
8823548a4e
commit
3289b6a887
2 changed files with 19 additions and 0 deletions
|
@ -130,6 +130,22 @@ bool File::is_directory(const String& filename)
|
||||||
return S_ISDIR(st.st_mode);
|
return S_ISDIR(st.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::is_link() const
|
||||||
|
{
|
||||||
|
struct stat stat;
|
||||||
|
if (fstat(fd(), &stat) < 0)
|
||||||
|
return false;
|
||||||
|
return S_ISLNK(stat.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool File::is_link(const String& filename)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (lstat(filename.characters(), &st) < 0)
|
||||||
|
return false;
|
||||||
|
return S_ISLNK(st.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
bool File::exists(const String& filename)
|
bool File::exists(const String& filename)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
|
@ -30,6 +30,9 @@ public:
|
||||||
bool is_device() const;
|
bool is_device() const;
|
||||||
static bool is_device(const String& filename);
|
static bool is_device(const String& filename);
|
||||||
|
|
||||||
|
bool is_link() const;
|
||||||
|
static bool is_link(const String& filename);
|
||||||
|
|
||||||
static bool exists(const String& filename);
|
static bool exists(const String& filename);
|
||||||
static bool ensure_parent_directories(const String& path);
|
static bool ensure_parent_directories(const String& path);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue