diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-12 21:17:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-12 21:17:00 +0100 |
commit | 90fec9c7327fcee65bf40342d303641709dca070 (patch) | |
tree | e2fb721e31a153276c5ded89e8901b958ee06f5a | |
parent | 0cdf68f6688f8bac1b69e4a2f5b5f27a5c24f938 (diff) | |
download | serenity-90fec9c7327fcee65bf40342d303641709dca070.zip |
LibCore: Add "static bool Core::File::exists(filename)"
-rw-r--r-- | Libraries/LibCore/File.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibCore/File.h | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibCore/File.cpp b/Libraries/LibCore/File.cpp index f12443ad2a..fd40d9b303 100644 --- a/Libraries/LibCore/File.cpp +++ b/Libraries/LibCore/File.cpp @@ -100,4 +100,10 @@ bool File::is_directory(const String& filename) return S_ISDIR(st.st_mode); } +bool File::exists(const String& filename) +{ + struct stat st; + return stat(filename.characters(), &st) == 0; +} + } diff --git a/Libraries/LibCore/File.h b/Libraries/LibCore/File.h index 51876e738a..fdfe6f785e 100644 --- a/Libraries/LibCore/File.h +++ b/Libraries/LibCore/File.h @@ -42,6 +42,8 @@ public: bool is_directory() const; static bool is_directory(const String& filename); + static bool exists(const String& filename); + virtual bool open(IODevice::OpenMode) override; enum class ShouldCloseFileDescription { |