diff options
30 files changed, 135 insertions, 134 deletions
diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp index f7a874c58f..e46a92132a 100644 --- a/Applications/Piano/main.cpp +++ b/Applications/Piano/main.cpp @@ -27,16 +27,16 @@ int main(int argc, char** argv) window->set_icon(load_png("/res/icons/16x16/app-piano.png")); LibThread::Thread sound_thread([piano_widget = piano_widget.ptr()] { - CFile audio("/dev/audio"); - if (!audio.open(CIODevice::WriteOnly)) { - dbgprintf("Can't open audio device: %s", audio.error_string()); + auto audio = CFile::construct("/dev/audio"); + if (!audio->open(CIODevice::WriteOnly)) { + dbgprintf("Can't open audio device: %s", audio->error_string()); return 1; } for (;;) { u8 buffer[4096]; piano_widget->fill_audio_buffer(buffer, sizeof(buffer)); - audio.write(buffer, sizeof(buffer)); + audio->write(buffer, sizeof(buffer)); GEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0)); GEventLoop::wake(); } diff --git a/Applications/SystemMonitor/DevicesModel.cpp b/Applications/SystemMonitor/DevicesModel.cpp index 0e0ff6bab6..fc67e60fc0 100644 --- a/Applications/SystemMonitor/DevicesModel.cpp +++ b/Applications/SystemMonitor/DevicesModel.cpp @@ -95,11 +95,11 @@ GVariant DevicesModel::data(const GModelIndex& index, Role) const void DevicesModel::update() { - CFile proc_devices { "/proc/devices" }; - if (!proc_devices.open(CIODevice::OpenMode::ReadOnly)) + auto proc_devices = CFile::construct("/proc/devices"); + if (!proc_devices->open(CIODevice::OpenMode::ReadOnly)) ASSERT_NOT_REACHED(); - auto json = JsonValue::from_string(proc_devices.read_all()).as_array(); + auto json = JsonValue::from_string(proc_devices->read_all()).as_array(); m_devices.clear(); json.for_each([this](auto& value) { diff --git a/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Applications/SystemMonitor/MemoryStatsWidget.cpp index 889bea9114..1c0594591c 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -11,9 +11,9 @@ MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent) : GWidget(parent) , m_graph(graph) - , m_proc_memstat("/proc/memstat") + , m_proc_memstat(CFile::construct("/proc/memstat")) { - if (!m_proc_memstat.open(CIODevice::OpenMode::ReadOnly)) + if (!m_proc_memstat->open(CIODevice::OpenMode::ReadOnly)) ASSERT_NOT_REACHED(); set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); set_preferred_size(0, 72); @@ -59,9 +59,9 @@ static inline size_t bytes_to_kb(size_t bytes) void MemoryStatsWidget::refresh() { - m_proc_memstat.seek(0); + m_proc_memstat->seek(0); - auto file_contents = m_proc_memstat.read_all(); + auto file_contents = m_proc_memstat->read_all(); auto json = JsonValue::from_string(file_contents).as_object(); unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_u32(); diff --git a/Applications/SystemMonitor/MemoryStatsWidget.h b/Applications/SystemMonitor/MemoryStatsWidget.h index 7762da38c9..32b5f27bf6 100644 --- a/Applications/SystemMonitor/MemoryStatsWidget.h +++ b/Applications/SystemMonitor/MemoryStatsWidget.h @@ -22,5 +22,5 @@ private: ObjectPtr<GLabel> m_supervisor_physical_pages_label; ObjectPtr<GLabel> m_kmalloc_label; ObjectPtr<GLabel> m_kmalloc_count_label; - CFile m_proc_memstat; + ObjectPtr<CFile> m_proc_memstat; }; diff --git a/Applications/SystemMonitor/ProcessStacksWidget.cpp b/Applications/SystemMonitor/ProcessStacksWidget.cpp index c54ffba358..73c94c4329 100644 --- a/Applications/SystemMonitor/ProcessStacksWidget.cpp +++ b/Applications/SystemMonitor/ProcessStacksWidget.cpp @@ -28,11 +28,11 @@ void ProcessStacksWidget::set_pid(pid_t pid) void ProcessStacksWidget::refresh() { - CFile file(String::format("/proc/%d/stack", m_pid)); - if (!file.open(CIODevice::ReadOnly)) { - m_stacks_editor->set_text(String::format("Unable to open %s", file.filename().characters())); + auto file = CFile::construct(String::format("/proc/%d/stack", m_pid)); + if (!file->open(CIODevice::ReadOnly)) { + m_stacks_editor->set_text(String::format("Unable to open %s", file->filename().characters())); return; } - m_stacks_editor->set_text(file.read_all()); + m_stacks_editor->set_text(file->read_all()); } diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index c149b36c06..50ba9b5b4c 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -270,14 +270,14 @@ void TextEditorWidget::update_title() void TextEditorWidget::open_sesame(const String& path) { - CFile file(path); - if (!file.open(CIODevice::ReadOnly)) { + auto file = CFile::construct(path); + if (!file->open(CIODevice::ReadOnly)) { GMessageBox::show(String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); return; } m_document_dirty = false; - m_editor->set_text(file.read_all()); + m_editor->set_text(file->read_all()); set_path(FileSystemPath(path)); } diff --git a/DevTools/FormCompiler/main.cpp b/DevTools/FormCompiler/main.cpp index 2e86550ff5..0b4dfafe39 100644 --- a/DevTools/FormCompiler/main.cpp +++ b/DevTools/FormCompiler/main.cpp @@ -13,13 +13,13 @@ int main(int argc, char** argv) return 0; } - CFile file(argv[1]); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error: Cannot open %s: %s\n", argv[1], file.error_string()); + auto file = CFile::construct(argv[1]); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error: Cannot open %s: %s\n", argv[1], file->error_string()); return 1; } - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); if (!json.is_object()) { diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index e1b78d93e5..87d140bba3 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -37,13 +37,13 @@ int main(int argc, char** argv) return 0; } - CFile file(argv[1]); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error: Cannot open %s: %s\n", argv[1], file.error_string()); + auto file = CFile::construct(argv[1]); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error: Cannot open %s: %s\n", argv[1], file->error_string()); return 1; } - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); Vector<Endpoint> endpoints; diff --git a/DevTools/VisualBuilder/VBForm.cpp b/DevTools/VisualBuilder/VBForm.cpp index e885eb96ed..cd0aad11de 100644 --- a/DevTools/VisualBuilder/VBForm.cpp +++ b/DevTools/VisualBuilder/VBForm.cpp @@ -356,13 +356,13 @@ void VBForm::mousemove_event(GMouseEvent& event) void VBForm::load_from_file(const String& path) { - CFile file(path); - if (!file.open(CIODevice::ReadOnly)) { + auto file = CFile::construct(path); + if (!file->open(CIODevice::ReadOnly)) { GMessageBox::show(String::format("Could not open '%s' for reading", path.characters()), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); return; } - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto form_json = JsonValue::from_string(file_contents); if (!form_json.is_object()) { @@ -392,8 +392,8 @@ void VBForm::load_from_file(const String& path) void VBForm::write_to_file(const String& path) { - CFile file(path); - if (!file.open(CIODevice::WriteOnly)) { + auto file = CFile::construct(path); + if (!file->open(CIODevice::WriteOnly)) { GMessageBox::show(String::format("Could not open '%s' for writing", path.characters()), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); return; } @@ -414,7 +414,7 @@ void VBForm::write_to_file(const String& path) widget_array.append(widget_object); } form_object.set("widgets", widget_array); - file.write(form_object.to_string()); + file->write(form_object.to_string()); } void VBForm::dump() 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); diff --git a/Servers/AudioServer/ASMixer.cpp b/Servers/AudioServer/ASMixer.cpp index 1b5219d171..7ca7839bf6 100644 --- a/Servers/AudioServer/ASMixer.cpp +++ b/Servers/AudioServer/ASMixer.cpp @@ -4,14 +4,14 @@ #include <limits> ASMixer::ASMixer() - : m_device("/dev/audio", this) + : m_device(CFile::construct("/dev/audio", this)) , m_sound_thread([this] { mix(); return 0; }) { - if (!m_device.open(CIODevice::WriteOnly)) { - dbgprintf("Can't open audio device: %s\n", m_device.error_string()); + if (!m_device->open(CIODevice::WriteOnly)) { + dbgprintf("Can't open audio device: %s\n", m_device->error_string()); return; } @@ -88,7 +88,7 @@ void ASMixer::mix() if (stream.offset() != 0) { buffer.trim(stream.offset()); - m_device.write(buffer); + m_device->write(buffer); } } } diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h index 0f2e869c05..9dfa618217 100644 --- a/Servers/AudioServer/ASMixer.h +++ b/Servers/AudioServer/ASMixer.h @@ -63,7 +63,7 @@ public: private: Vector<NonnullRefPtr<ASBufferQueue>> m_pending_mixing; - CFile m_device; + ObjectPtr<CFile> m_device; LibThread::Lock m_lock; LibThread::Thread m_sound_thread; diff --git a/Servers/LookupServer/main.cpp b/Servers/LookupServer/main.cpp index 740657d53d..1c3dec89c5 100644 --- a/Servers/LookupServer/main.cpp +++ b/Servers/LookupServer/main.cpp @@ -35,11 +35,11 @@ static String parse_dns_name(const u8*, int& offset, int max_offset); static void load_etc_hosts() { dbgprintf("LookupServer: Loading hosts from /etc/hosts\n"); - CFile file("/etc/hosts"); - if (!file.open(CIODevice::ReadOnly)) + auto file = CFile::construct("/etc/hosts"); + if (!file->open(CIODevice::ReadOnly)) return; - while (!file.eof()) { - auto line = file.read_line(1024); + while (!file->eof()) { + auto line = file->read_line(1024); if (line.is_empty()) break; auto str_line = String((const char*)line.pointer(), line.size() - 1, Chomp); diff --git a/Servers/SystemServer/main.cpp b/Servers/SystemServer/main.cpp index a70d70bbd1..68974780c6 100644 --- a/Servers/SystemServer/main.cpp +++ b/Servers/SystemServer/main.cpp @@ -58,12 +58,12 @@ void start_process(const String& program, const Vector<String>& arguments, int p static void check_for_test_mode() { - CFile f("/proc/cmdline"); - if (!f.open(CIODevice::ReadOnly)) { - dbg() << "Failed to read command line: " << f.error_string(); + auto f = CFile::construct("/proc/cmdline"); + if (!f->open(CIODevice::ReadOnly)) { + dbg() << "Failed to read command line: " << f->error_string(); ASSERT(false); } - const String cmd = String::copy(f.read_all()); + const String cmd = String::copy(f->read_all()); dbg() << "Read command line: " << cmd; if (cmd.matches("*testmode=1*")) { // Eventually, we should run a test binary and wait for it to finish diff --git a/Shell/main.cpp b/Shell/main.cpp index 8c236416f6..78aed03172 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -814,11 +814,11 @@ static String get_history_path() void load_history() { - CFile history_file(get_history_path()); - if (!history_file.open(CIODevice::ReadOnly)) + auto history_file = CFile::construct(get_history_path()); + if (!history_file->open(CIODevice::ReadOnly)) return; - while (history_file.can_read_line()) { - auto b = history_file.read_line(1024); + while (history_file->can_read_line()) { + auto b = history_file->read_line(1024); // skip the newline and terminating bytes editor.add_to_history(String(reinterpret_cast<const char*>(b.pointer()), b.size() - 2)); } @@ -826,12 +826,12 @@ void load_history() void save_history() { - CFile history_file(get_history_path()); - if (!history_file.open(CIODevice::WriteOnly)) + auto history_file = CFile::construct(get_history_path()); + if (!history_file->open(CIODevice::WriteOnly)) return; for (const auto& line : editor.history()) { - history_file.write(line); - history_file.write("\n"); + history_file->write(line); + history_file->write("\n"); } } @@ -878,13 +878,13 @@ int main(int argc, char** argv) } if (argc == 2 && argv[1][0] != '-') { - CFile file(argv[1]); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Failed to open %s: %s\n", file.filename().characters(), file.error_string()); + auto file = CFile::construct(argv[1]); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Failed to open %s: %s\n", file->filename().characters(), file->error_string()); return 1; } for (;;) { - auto line = file.read_line(4096); + auto line = file->read_line(4096); if (line.is_null()) break; run_command(String::copy(line, Chomp)); diff --git a/Userland/copy.cpp b/Userland/copy.cpp index 991f43c1b7..ddad0a5ffa 100644 --- a/Userland/copy.cpp +++ b/Userland/copy.cpp @@ -68,13 +68,13 @@ Options parse_options(int argc, char* argv[]) options.data = builder.to_string(); } else { // Copy our stdin. - CFile c_stdin; - bool success = c_stdin.open( + auto c_stdin = CFile::construct(); + bool success = c_stdin->open( STDIN_FILENO, CIODevice::OpenMode::ReadOnly, CFile::ShouldCloseFileDescription::No); ASSERT(success); - auto buffer = c_stdin.read_all(); + auto buffer = c_stdin->read_all(); dbg() << "Read size " << buffer.size(); options.data = String((char*)buffer.data(), buffer.size()); } diff --git a/Userland/df.cpp b/Userland/df.cpp index 60aef65120..eca965bdea 100644 --- a/Userland/df.cpp +++ b/Userland/df.cpp @@ -19,14 +19,14 @@ struct FileSystem { int main(int, char**) { - CFile file("/proc/df"); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Failed to open /proc/df: %s\n", file.error_string()); + auto file = CFile::construct("/proc/df"); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Failed to open /proc/df: %s\n", file->error_string()); return 1; } printf("Filesystem Blocks Used Available Mount point\n"); - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents).as_array(); json.for_each([](auto& value) { auto fs_object = value.as_object(); diff --git a/Userland/dmesg.cpp b/Userland/dmesg.cpp index bc558815fc..afe90b1b0b 100644 --- a/Userland/dmesg.cpp +++ b/Userland/dmesg.cpp @@ -8,12 +8,12 @@ int main(int argc, char** argv) { (void)argc; (void)argv; - CFile f("/proc/dmesg"); - if (!f.open(CIODevice::ReadOnly)) { - fprintf(stderr, "open: failed to open /proc/dmesg: %s", f.error_string()); + auto f = CFile::construct("/proc/dmesg"); + if (!f->open(CIODevice::ReadOnly)) { + fprintf(stderr, "open: failed to open /proc/dmesg: %s", f->error_string()); return 1; } - const auto& b = f.read_all(); + const auto& b = f->read_all(); for (auto i = 0; i < b.size(); ++i) putchar(b[i]); return 0; diff --git a/Userland/ifconfig.cpp b/Userland/ifconfig.cpp index e53b9715ca..4b6f303e54 100644 --- a/Userland/ifconfig.cpp +++ b/Userland/ifconfig.cpp @@ -21,13 +21,13 @@ int main(int argc, char** argv) UNUSED_PARAM(argc); UNUSED_PARAM(argv); - CFile file("/proc/net/adapters"); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error: %s\n", file.error_string()); + auto file = CFile::construct("/proc/net/adapters"); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error: %s\n", file->error_string()); return 1; } - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents).as_array(); json.for_each([](auto& value) { auto if_object = value.as_object(); diff --git a/Userland/jp.cpp b/Userland/jp.cpp index 023a12085f..4e2dd8cda6 100644 --- a/Userland/jp.cpp +++ b/Userland/jp.cpp @@ -18,13 +18,13 @@ int main(int argc, char** argv) fprintf(stderr, "usage: jp <file>\n"); return 0; } - CFile file(argv[1]); - if (!file.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Couldn't open %s for reading: %s\n", argv[1], file.error_string()); + auto file = CFile::construct(argv[1]); + if (!file->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Couldn't open %s for reading: %s\n", argv[1], file->error_string()); return 1; } - auto file_contents = file.read_all(); + auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); print(json); diff --git a/Userland/lspci.cpp b/Userland/lspci.cpp index d40b9de83b..6f35ec97d5 100644 --- a/Userland/lspci.cpp +++ b/Userland/lspci.cpp @@ -14,13 +14,13 @@ int main(int argc, char** argv) if (!db) fprintf(stderr, "Couldn't open PCI ID database\n"); - CFile proc_pci("/proc/pci"); - if (!proc_pci.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error: %s\n", proc_pci.error_string()); + auto proc_pci = CFile::construct("/proc/pci"); + if (!proc_pci->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error: %s\n", proc_pci->error_string()); return 1; } - auto file_contents = proc_pci.read_all(); + auto file_contents = proc_pci->read_all(); auto json = JsonValue::from_string(file_contents).as_array(); json.for_each([db](auto& value) { auto dev = value.as_object(); diff --git a/Userland/mount.cpp b/Userland/mount.cpp index 16969b716c..ec99287ae1 100644 --- a/Userland/mount.cpp +++ b/Userland/mount.cpp @@ -11,15 +11,15 @@ bool mount_all() // Mount all filesystems listed in /etc/fstab. dbg() << "Mounting all filesystems..."; - CFile fstab { "/etc/fstab" }; - if (!fstab.open(CIODevice::OpenMode::ReadOnly)) { - fprintf(stderr, "Failed to open /etc/fstab: %s\n", fstab.error_string()); + auto fstab = CFile::construct("/etc/fstab"); + if (!fstab->open(CIODevice::OpenMode::ReadOnly)) { + fprintf(stderr, "Failed to open /etc/fstab: %s\n", fstab->error_string()); return false; } bool all_ok = true; - while (fstab.can_read_line()) { - ByteBuffer buffer = fstab.read_line(1024); + while (fstab->can_read_line()) { + ByteBuffer buffer = fstab->read_line(1024); StringView line_view = (const char*)buffer.data(); // Trim the trailing newline, if any. @@ -59,13 +59,13 @@ bool mount_all() bool print_mounts() { // Output info about currently mounted filesystems. - CFile df("/proc/df"); - if (!df.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Failed to open /proc/df: %s\n", df.error_string()); + auto df = CFile::construct("/proc/df"); + if (!df->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Failed to open /proc/df: %s\n", df->error_string()); return false; } - auto content = df.read_all(); + auto content = df->read_all(); auto json = JsonValue::from_string(content).as_array(); json.for_each([](auto& value) { diff --git a/Userland/sysctl.cpp b/Userland/sysctl.cpp index 96d0f7a790..ce11eb1921 100644 --- a/Userland/sysctl.cpp +++ b/Userland/sysctl.cpp @@ -17,14 +17,14 @@ static String read_var(const String& name) builder.append("/proc/sys/"); builder.append(name); auto path = builder.to_string(); - CFile f(path); - if (!f.open(CIODevice::ReadOnly)) { - fprintf(stderr, "open: %s", f.error_string()); + auto f = CFile::construct(path); + if (!f->open(CIODevice::ReadOnly)) { + fprintf(stderr, "open: %s", f->error_string()); exit(1); } - const auto& b = f.read_all(); - if (f.error() < 0) { - fprintf(stderr, "read: %s", f.error_string()); + const auto& b = f->read_all(); + if (f->error() < 0) { + fprintf(stderr, "read: %s", f->error_string()); exit(1); } return String((const char*)b.pointer(), b.size(), Chomp); @@ -36,14 +36,14 @@ static void write_var(const String& name, const String& value) builder.append("/proc/sys/"); builder.append(name); auto path = builder.to_string(); - CFile f(path); - if (!f.open(CIODevice::WriteOnly)) { - fprintf(stderr, "open: %s", f.error_string()); + auto f = CFile::construct(path); + if (!f->open(CIODevice::WriteOnly)) { + fprintf(stderr, "open: %s", f->error_string()); exit(1); } - f.write(value); - if (f.error() < 0) { - fprintf(stderr, "write: %s", f.error_string()); + f->write(value); + if (f->error() < 0) { + fprintf(stderr, "write: %s", f->error_string()); exit(1); } } diff --git a/Userland/tail.cpp b/Userland/tail.cpp index a1b8b03620..1822d9705e 100644 --- a/Userland/tail.cpp +++ b/Userland/tail.cpp @@ -95,13 +95,13 @@ int main(int argc, char* argv[]) line_count = DEFAULT_LINE_COUNT; } - CFile f(values[0]); - if (!f.open(CIODevice::ReadOnly)) { - fprintf(stderr, "Error opening file %s: %s\n", f.filename().characters(), strerror(errno)); + auto f = CFile::construct(values[0]); + if (!f->open(CIODevice::ReadOnly)) { + fprintf(stderr, "Error opening file %s: %s\n", f->filename().characters(), strerror(errno)); exit(1); } bool flag_follow = args.is_present("f"); - auto pos = find_seek_pos(f, line_count); - return tail_from_pos(f, pos, flag_follow); + auto pos = find_seek_pos(*f, line_count); + return tail_from_pos(*f, pos, flag_follow); } |