diff options
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibAudio/AWavLoader.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibAudio/AWavLoader.h | 2 | ||||
-rw-r--r-- | Libraries/LibCore/CConfigFile.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibCore/CFile.h | 11 | ||||
-rw-r--r-- | Libraries/LibCore/CProcessStatisticsReader.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibGUI/GJsonArrayModel.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibHTML/test.cpp | 8 |
7 files changed, 28 insertions, 27 deletions
diff --git a/Libraries/LibAudio/AWavLoader.cpp b/Libraries/LibAudio/AWavLoader.cpp index f241cfe134..6315a8c3c2 100644 --- a/Libraries/LibAudio/AWavLoader.cpp +++ b/Libraries/LibAudio/AWavLoader.cpp @@ -6,10 +6,10 @@ #include <limits> AWavLoader::AWavLoader(const StringView& path) - : m_file(path) + : m_file(CFile::construct(path)) { - if (!m_file.open(CIODevice::ReadOnly)) { - m_error_string = String::format("Can't open file: %s", m_file.error_string()); + if (!m_file->open(CIODevice::ReadOnly)) { + m_error_string = String::format("Can't open file: %s", m_file->error_string()); return; } @@ -22,7 +22,7 @@ RefPtr<ABuffer> AWavLoader::get_more_samples(size_t max_bytes_to_read_from_input dbgprintf("Read WAV of format PCM with num_channels %u sample rate %u, bits per sample %u\n", m_num_channels, m_sample_rate, m_bits_per_sample); #endif - auto raw_samples = m_file.read(max_bytes_to_read_from_input); + auto raw_samples = m_file->read(max_bytes_to_read_from_input); if (raw_samples.is_empty()) return nullptr; @@ -33,7 +33,7 @@ RefPtr<ABuffer> AWavLoader::get_more_samples(size_t max_bytes_to_read_from_input bool AWavLoader::parse_header() { - CIODeviceStreamReader stream(m_file); + CIODeviceStreamReader stream(*m_file); #define CHECK_OK(msg) \ do { \ diff --git a/Libraries/LibAudio/AWavLoader.h b/Libraries/LibAudio/AWavLoader.h index 45c13a4573..ac18e58ba2 100644 --- a/Libraries/LibAudio/AWavLoader.h +++ b/Libraries/LibAudio/AWavLoader.h @@ -29,7 +29,7 @@ public: private: bool parse_header(); - CFile m_file; + ObjectPtr<CFile> m_file; String m_error_string; u32 m_sample_rate { 0 }; diff --git a/Libraries/LibCore/CConfigFile.cpp b/Libraries/LibCore/CConfigFile.cpp index 2f1fec736a..7d53a27044 100644 --- a/Libraries/LibCore/CConfigFile.cpp +++ b/Libraries/LibCore/CConfigFile.cpp @@ -36,14 +36,14 @@ void CConfigFile::reparse() { m_groups.clear(); - CFile file(m_file_name); - if (!file.open(CIODevice::OpenMode::ReadOnly)) + auto file = CFile::construct(m_file_name); + if (!file->open(CIODevice::OpenMode::ReadOnly)) return; HashMap<String, String>* current_group = nullptr; - while (file.can_read_line()) { - auto line = file.read_line(BUFSIZ); + while (file->can_read_line()) { + auto line = file->read_line(BUFSIZ); auto* cp = (const char*)line.pointer(); while (*cp && (*cp == ' ' || *cp == '\t' || *cp == '\n')) diff --git a/Libraries/LibCore/CFile.h b/Libraries/LibCore/CFile.h index d83d20ef9d..cf16077ec3 100644 --- a/Libraries/LibCore/CFile.h +++ b/Libraries/LibCore/CFile.h @@ -6,11 +6,6 @@ class CFile final : public CIODevice { C_OBJECT(CFile) public: - CFile(CObject* parent = nullptr) - : CIODevice(parent) - { - } - explicit CFile(const StringView&, CObject* parent = nullptr); virtual ~CFile() override; String filename() const { return m_filename; } @@ -25,6 +20,12 @@ public: bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescription); private: + CFile(CObject* parent = nullptr) + : CIODevice(parent) + { + } + explicit CFile(const StringView&, CObject* parent = nullptr); + String m_filename; ShouldCloseFileDescription m_should_close_file_descriptor { ShouldCloseFileDescription::Yes }; }; diff --git a/Libraries/LibCore/CProcessStatisticsReader.cpp b/Libraries/LibCore/CProcessStatisticsReader.cpp index bb904c087b..aaf1fb7e04 100644 --- a/Libraries/LibCore/CProcessStatisticsReader.cpp +++ b/Libraries/LibCore/CProcessStatisticsReader.cpp @@ -10,15 +10,15 @@ HashMap<uid_t, String> CProcessStatisticsReader::s_usernames; HashMap<pid_t, CProcessStatistics> CProcessStatisticsReader::get_all() { - CFile file("/proc/all"); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "CProcessStatisticsReader: Failed to open /proc/all: %s\n", file.error_string()); + auto file = CFile::construct("/proc/all"); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "CProcessStatisticsReader: Failed to open /proc/all: %s\n", file->error_string()); return {}; } HashMap<pid_t, CProcessStatistics> map; - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() }); json.as_array().for_each([&](auto& value) { const JsonObject& process_object = value.as_object(); diff --git a/Libraries/LibGUI/GJsonArrayModel.cpp b/Libraries/LibGUI/GJsonArrayModel.cpp index d819518f92..9a6a7dbc36 100644 --- a/Libraries/LibGUI/GJsonArrayModel.cpp +++ b/Libraries/LibGUI/GJsonArrayModel.cpp @@ -4,13 +4,13 @@ void GJsonArrayModel::update() { - CFile file(m_json_path); - if (!file.open(CIODevice::ReadOnly)) { - dbg() << "Unable to open " << file.filename(); + auto file = CFile::construct(m_json_path); + if (!file->open(CIODevice::ReadOnly)) { + dbg() << "Unable to open " << file->filename(); return; } - auto json = JsonValue::from_string(file.read_all()); + auto json = JsonValue::from_string(file->read_all()); ASSERT(json.is_array()); m_array = json.as_array(); diff --git a/Libraries/LibHTML/test.cpp b/Libraries/LibHTML/test.cpp index e3e052ff36..f10f9b9679 100644 --- a/Libraries/LibHTML/test.cpp +++ b/Libraries/LibHTML/test.cpp @@ -12,9 +12,9 @@ int main(int argc, char** argv) { - CFile f(argc == 1 ? "/home/anon/small.html" : argv[1]); - if (!f.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error: %s\n", f.error_string()); + auto f = CFile::construct(argc == 1 ? "/home/anon/small.html" : argv[1]); + if (!f->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error: %s\n", f->error_string()); return 1; } @@ -24,7 +24,7 @@ int main(int argc, char** argv) auto sheet = parse_css(css); dump_sheet(sheet); - String html = String::copy(f.read_all()); + String html = String::copy(f->read_all()); auto document = parse_html(html); dump_tree(document); document->add_sheet(*sheet); |