diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 20:50:06 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 20:50:06 +0200 |
commit | 8d550c174edad68726b8e9c3cd5cd950bf1bf16a (patch) | |
tree | 2c6ed4bd36844e7df4bfc787ea6b23d71902f346 /Userland | |
parent | 31b38ed88f3db123c498379f4615d2dce1ded406 (diff) | |
download | serenity-8d550c174edad68726b8e9c3cd5cd950bf1bf16a.zip |
LibCore: Convert CFile to ObjectPtr
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/copy.cpp | 6 | ||||
-rw-r--r-- | Userland/df.cpp | 8 | ||||
-rw-r--r-- | Userland/dmesg.cpp | 8 | ||||
-rw-r--r-- | Userland/ifconfig.cpp | 8 | ||||
-rw-r--r-- | Userland/jp.cpp | 8 | ||||
-rw-r--r-- | Userland/lspci.cpp | 8 | ||||
-rw-r--r-- | Userland/mount.cpp | 18 | ||||
-rw-r--r-- | Userland/sysctl.cpp | 24 | ||||
-rw-r--r-- | Userland/tail.cpp | 10 |
9 files changed, 49 insertions, 49 deletions
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); } |