diff options
author | Ariel Don <ariel@arieldon.com> | 2022-05-15 10:36:19 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-05-21 18:15:00 +0200 |
commit | 244357472a5d9d0d9ddf507472fb220be00eae95 (patch) | |
tree | d16c5eec133d15bdb1173813744f5e35e331499b | |
parent | 8a854ba309a591254935559e72c44dca98c9a05e (diff) | |
download | serenity-244357472a5d9d0d9ddf507472fb220be00eae95.zip |
LibCore: Add Core::Stream::File::exists()
-rw-r--r-- | Userland/Libraries/LibCore/Stream.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/Stream.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index 179ee209ea..c142bfb685 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -117,6 +117,11 @@ ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode) return file; } +bool File::exists(StringView filename) +{ + return !Core::System::stat(filename).is_error(); +} + int File::open_mode_to_options(OpenMode mode) { int flags = 0; diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index 1859e86a59..2089fdac49 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -179,6 +179,7 @@ class File final : public SeekableStream { public: static ErrorOr<NonnullOwnPtr<File>> open(StringView filename, OpenMode, mode_t = 0644); static ErrorOr<NonnullOwnPtr<File>> adopt_fd(int fd, OpenMode); + static bool exists(StringView filename); File(File&& other) { operator=(move(other)); } |