mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:07:35 +00:00
LibCore: Convert CFile to ObjectPtr
This commit is contained in:
parent
31b38ed88f
commit
8d550c174e
30 changed files with 135 additions and 134 deletions
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue