summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-21 13:29:36 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-21 16:19:18 +0200
commita19690170f879ee16df5dd910064b00b92f793ca (patch)
tree0be176a7f7cf6f40c06c3e07616499fc937ea04b /Libraries/LibCore
parentba3b561a40af8de42468e7987b8d84884294bf76 (diff)
downloadserenity-a19690170f879ee16df5dd910064b00b92f793ca.zip
LibCore: Make Core::File::open() return a Result<NNRP<File>, String>
It was impractical to return a RefPtr<File> since that left us no way to extract the error string. This is usually needed for the UI, so the old static open() got basically no use.
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/File.cpp4
-rw-r--r--Libraries/LibCore/File.h3
2 files changed, 4 insertions, 3 deletions
diff --git a/Libraries/LibCore/File.cpp b/Libraries/LibCore/File.cpp
index 782960407c..41056701f0 100644
--- a/Libraries/LibCore/File.cpp
+++ b/Libraries/LibCore/File.cpp
@@ -33,11 +33,11 @@
namespace Core {
-RefPtr<File> File::open(const String& filename, IODevice::OpenMode mode, mode_t permissions)
+Result<NonnullRefPtr<File>, String> File::open(const String& filename, IODevice::OpenMode mode, mode_t permissions)
{
auto file = File::construct(filename);
if (!file->open_impl(mode, permissions))
- return nullptr;
+ return String(file->error_string());
return file;
}
diff --git a/Libraries/LibCore/File.h b/Libraries/LibCore/File.h
index aa94dc35cf..1e443debef 100644
--- a/Libraries/LibCore/File.h
+++ b/Libraries/LibCore/File.h
@@ -26,6 +26,7 @@
#pragma once
+#include <AK/Result.h>
#include <AK/String.h>
#include <LibCore/IODevice.h>
@@ -36,7 +37,7 @@ class File final : public IODevice {
public:
virtual ~File() override;
- static RefPtr<File> open(const String& filename, IODevice::OpenMode, mode_t = 0644);
+ static Result<NonnullRefPtr<File>, String> open(const String& filename, IODevice::OpenMode, mode_t = 0644);
String filename() const { return m_filename; }
void set_filename(const StringView& filename) { m_filename = filename; }