diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index 0f30a995cb..8cdb47130a 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -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; diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index cb81920d1d..86738aba94 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -30,6 +30,9 @@ public: bool is_device() const; 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 ensure_parent_directories(const String& path);