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:
Ariel Don 2021-07-11 15:38:55 -05:00 committed by Ali Mohammad Pur
commit 3289b6a887
Notes: sideshowbarker 2024-07-18 09:10:50 +09:00
2 changed files with 19 additions and 0 deletions

View file

@ -130,6 +130,22 @@ bool File::is_directory(const String& filename)
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)
{
struct stat st;