mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:57:44 +00:00
LibCore: Move Core::Stream::File::exists()
to Core::File
`Core::Stream::File` shouldn't hold any utility methods that are unrelated to constructing a `Core::Stream`, so let's just replace the existing `Core::File::exists` with the nicer looking implementation.
This commit is contained in:
parent
bd272e638c
commit
2fc2025f49
10 changed files with 14 additions and 18 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/ScopeGuard.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
|
@ -191,10 +192,9 @@ bool File::looks_like_shared_library(DeprecatedString const& filename)
|
|||
return filename.ends_with(".so"sv) || filename.contains(".so."sv);
|
||||
}
|
||||
|
||||
bool File::exists(DeprecatedString const& filename)
|
||||
bool File::exists(StringView filename)
|
||||
{
|
||||
struct stat st;
|
||||
return stat(filename.characters(), &st) == 0;
|
||||
return !Core::System::stat(filename).is_error();
|
||||
}
|
||||
|
||||
ErrorOr<size_t> File::size(DeprecatedString const& filename)
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
bool looks_like_shared_library() const;
|
||||
static bool looks_like_shared_library(DeprecatedString const& filename);
|
||||
|
||||
static bool exists(DeprecatedString const& filename);
|
||||
static bool exists(StringView filename);
|
||||
static ErrorOr<size_t> size(DeprecatedString const& filename);
|
||||
static DeprecatedString current_working_directory();
|
||||
static DeprecatedString absolute_path(DeprecatedString const& path);
|
||||
|
|
|
@ -165,11 +165,6 @@ ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode, ShouldCloseFi
|
|||
return file;
|
||||
}
|
||||
|
||||
bool File::exists(StringView filename)
|
||||
{
|
||||
return !Core::System::stat(filename).is_error();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<File>> File::standard_input()
|
||||
{
|
||||
return File::adopt_fd(STDIN_FILENO, OpenMode::Read, ShouldCloseFileDescriptor::No);
|
||||
|
|
|
@ -220,7 +220,6 @@ 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, ShouldCloseFileDescriptor = ShouldCloseFileDescriptor::Yes);
|
||||
static bool exists(StringView filename);
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_input();
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_output();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue