mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
LibCore: Make Core::File::open() return OSError in case of failure
This commit is contained in:
parent
1474a537b6
commit
13f4890c38
8 changed files with 15 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -27,11 +27,11 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
Result<NonnullRefPtr<File>, String> File::open(String filename, OpenMode mode, mode_t permissions)
|
||||
Result<NonnullRefPtr<File>, OSError> File::open(String filename, OpenMode mode, mode_t permissions)
|
||||
{
|
||||
auto file = File::construct(move(filename));
|
||||
if (!file->open_impl(mode, permissions))
|
||||
return String(file->error_string());
|
||||
return OSError(file->error());
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@ class File final : public IODevice {
|
|||
public:
|
||||
virtual ~File() override;
|
||||
|
||||
static Result<NonnullRefPtr<File>, String> open(String filename, OpenMode, mode_t = 0644);
|
||||
static Result<NonnullRefPtr<File>, OSError> open(String filename, OpenMode, mode_t = 0644);
|
||||
|
||||
String filename() const { return m_filename; }
|
||||
void set_filename(const String filename) { m_filename = move(filename); }
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
static Result<InputFileStream, String> open(StringView filename, OpenMode mode = OpenMode::ReadOnly, mode_t permissions = 0644)
|
||||
static Result<InputFileStream, OSError> open(StringView filename, OpenMode mode = OpenMode::ReadOnly, mode_t permissions = 0644)
|
||||
{
|
||||
VERIFY(has_flag(mode, OpenMode::ReadOnly));
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
return InputFileStream { file_result.value() };
|
||||
}
|
||||
|
||||
static Result<Buffered<InputFileStream>, String> open_buffered(StringView filename, OpenMode mode = OpenMode::ReadOnly, mode_t permissions = 0644)
|
||||
static Result<Buffered<InputFileStream>, OSError> open_buffered(StringView filename, OpenMode mode = OpenMode::ReadOnly, mode_t permissions = 0644)
|
||||
{
|
||||
VERIFY(has_flag(mode, OpenMode::ReadOnly));
|
||||
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
static Result<OutputFileStream, String> open(StringView filename, OpenMode mode = OpenMode::WriteOnly, mode_t permissions = 0644)
|
||||
static Result<OutputFileStream, OSError> open(StringView filename, OpenMode mode = OpenMode::WriteOnly, mode_t permissions = 0644)
|
||||
{
|
||||
VERIFY(has_flag(mode, OpenMode::WriteOnly));
|
||||
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
return OutputFileStream { file_result.value() };
|
||||
}
|
||||
|
||||
static Result<Buffered<OutputFileStream>, String> open_buffered(StringView filename, OpenMode mode = OpenMode::WriteOnly, mode_t permissions = 0644)
|
||||
static Result<Buffered<OutputFileStream>, OSError> open_buffered(StringView filename, OpenMode mode = OpenMode::WriteOnly, mode_t permissions = 0644)
|
||||
{
|
||||
VERIFY(has_flag(mode, OpenMode::WriteOnly));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue