mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:37:35 +00:00
LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
This commit is contained in:
parent
422ef7904e
commit
a91a49337c
113 changed files with 180 additions and 177 deletions
|
@ -22,7 +22,7 @@ int main(int argc, char** argv)
|
|||
if (!path)
|
||||
path = "Source/little/main.cpp";
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
int main(int, char**)
|
||||
{
|
||||
auto file = Core::File::construct("/home/anon/Source/little/other.h");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
int main()
|
||||
{
|
||||
auto file = Core::File::construct("/proc/net/arp");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ int main(int argc, char** argv)
|
|||
auto file = Core::File::construct();
|
||||
bool success = file->open(
|
||||
STDIN_FILENO,
|
||||
Core::IODevice::OpenMode::ReadOnly,
|
||||
Core::OpenMode::ReadOnly,
|
||||
Core::File::ShouldCloseFileDescriptor::Yes);
|
||||
VERIFY(success);
|
||||
buffer = file->read_all();
|
||||
} else {
|
||||
auto result = Core::File::open(filepath, Core::IODevice::OpenMode::ReadOnly);
|
||||
auto result = Core::File::open(filepath, Core::OpenMode::ReadOnly);
|
||||
VERIFY(!result.is_error());
|
||||
auto file = result.value();
|
||||
buffer = file->read_all();
|
||||
|
|
|
@ -54,10 +54,10 @@ int main(int argc, char** argv)
|
|||
|
||||
for (auto const& path : paths) {
|
||||
if (path == "-") {
|
||||
success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
||||
success = file->open(STDIN_FILENO, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
||||
} else {
|
||||
file->set_filename(path);
|
||||
success = file->open(Core::IODevice::OpenMode::ReadOnly);
|
||||
success = file->open(Core::OpenMode::ReadOnly);
|
||||
}
|
||||
if (!success) {
|
||||
warnln("{}: {}: {}", argv[0], path, file->error_string());
|
||||
|
|
|
@ -42,7 +42,7 @@ int main(int argc, char** argv)
|
|||
bool fail = false;
|
||||
for (auto& path : paths) {
|
||||
auto file = Core::File::construct((StringView(path) == "-") ? "/dev/stdin" : path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("{}: {}: {}", argv[0], path, file->error_string());
|
||||
fail = true;
|
||||
continue;
|
||||
|
|
|
@ -43,7 +43,7 @@ static Options parse_options(int argc, char* argv[])
|
|||
auto c_stdin = Core::File::construct();
|
||||
bool success = c_stdin->open(
|
||||
STDIN_FILENO,
|
||||
Core::IODevice::OpenMode::ReadOnly,
|
||||
Core::OpenMode::ReadOnly,
|
||||
Core::File::ShouldCloseFileDescriptor::No);
|
||||
VERIFY(success);
|
||||
auto buffer = c_stdin->read_all();
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
|||
args_parser.parse(argc, argv);
|
||||
|
||||
auto file = Core::File::construct("/proc/df");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Failed to open /proc/df: %s\n", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
unveil(nullptr, nullptr);
|
||||
|
||||
auto f = Core::File::construct("/proc/dmesg");
|
||||
if (!f->open(Core::IODevice::ReadOnly)) {
|
||||
if (!f->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "open: failed to open /proc/dmesg: %s\n", f->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ int parse_args(int argc, char** argv, Vector<String>& files, DuOption& du_option
|
|||
du_option.excluded_patterns.append(pattern);
|
||||
if (exclude_from) {
|
||||
auto file = Core::File::construct(exclude_from);
|
||||
bool success = file->open(Core::IODevice::ReadOnly);
|
||||
bool success = file->open(Core::OpenMode::ReadOnly);
|
||||
VERIFY(success);
|
||||
if (const auto buff = file->read_all()) {
|
||||
String patterns = String::copy(buff, Chomp);
|
||||
|
|
|
@ -96,7 +96,7 @@ int main(int argc, char** argv)
|
|||
|
||||
for (auto path : paths) {
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::File::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
perror(path);
|
||||
all_ok = false;
|
||||
continue;
|
||||
|
|
|
@ -84,7 +84,7 @@ int main(int argc, char** argv)
|
|||
args_parser.parse(argc, argv);
|
||||
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Couldn't open {} for reading: {}", path, file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ bool format_file(const StringView& path, bool inplace)
|
|||
if (read_from_stdin) {
|
||||
file = Core::File::standard_input();
|
||||
} else {
|
||||
auto open_mode = inplace ? Core::File::ReadWrite : Core::File::ReadOnly;
|
||||
auto open_mode = inplace ? Core::OpenMode::ReadWrite : Core::OpenMode::ReadOnly;
|
||||
auto file_or_error = Core::File::open(path, open_mode);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Could not open {}: {}", path, file_or_error.error());
|
||||
|
|
|
@ -140,7 +140,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto handle_file = [&matches, binary_mode](StringView filename, bool print_filename) -> bool {
|
||||
auto file = Core::File::construct(filename);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Failed to open {}: {}", filename, file->error_string());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
auto file = Core::File::construct(argv[1]);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Couldn't open %s for reading: %s\n", argv[1], file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ int main(int argc, char** argv)
|
|||
if (!path) {
|
||||
file = Core::File::standard_input();
|
||||
} else {
|
||||
auto file_or_error = Core::File::open(path, Core::File::ReadOnly);
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, file_or_error.error());
|
||||
return 1;
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
|||
if (!value_ipv4 && !value_adapter && !value_gateway && !value_mask) {
|
||||
|
||||
auto file = Core::File::construct("/proc/net/adapters");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ int main(int argc, char** argv)
|
|||
if (path == nullptr)
|
||||
path = "/dev/stdin";
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Couldn't open {} for reading: {}", path, file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -587,7 +587,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file)
|
|||
for (auto& file : vm.call_frame().arguments) {
|
||||
String filename = file.as_string().string();
|
||||
auto js_file = Core::File::construct(filename);
|
||||
if (!js_file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!js_file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Failed to open {}: {}", filename, js_file->error_string());
|
||||
continue;
|
||||
}
|
||||
|
@ -969,7 +969,7 @@ int main(int argc, char** argv)
|
|||
});
|
||||
|
||||
auto file = Core::File::construct(script_path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Failed to open {}: {}", script_path, file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
unveil(nullptr, nullptr);
|
||||
|
||||
auto proc_interrupts = Core::File::construct("/proc/interrupts");
|
||||
if (!proc_interrupts->open(Core::IODevice::ReadOnly)) {
|
||||
if (!proc_interrupts->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", proc_interrupts->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ static bool parse_name(StringView name, OpenFile& file)
|
|||
|
||||
static Vector<OpenFile> get_open_files_by_pid(pid_t pid)
|
||||
{
|
||||
auto file = Core::File::open(String::formatted("/proc/{}/fds", pid), Core::IODevice::OpenMode::ReadOnly);
|
||||
auto file = Core::File::open(String::formatted("/proc/{}/fds", pid), Core::OpenMode::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
printf("lsof: PID %d: %s\n", pid, file.error().characters());
|
||||
return Vector<OpenFile>();
|
||||
|
|
|
@ -55,7 +55,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
auto proc_pci = Core::File::construct("/proc/pci");
|
||||
if (!proc_pci->open(Core::IODevice::ReadOnly)) {
|
||||
if (!proc_pci->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", proc_pci->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ int main(int argc, char* argv[])
|
|||
auto file = Core::File::construct();
|
||||
file->set_filename(make_path(section));
|
||||
|
||||
if (!file->open(Core::IODevice::OpenMode::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
perror("Failed to open man page file");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ int main(int argc, char* argv[])
|
|||
auto file = Core::File::construct();
|
||||
bool success;
|
||||
if (filename == nullptr) {
|
||||
success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
||||
success = file->open(STDIN_FILENO, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
|
||||
} else {
|
||||
file->set_filename(filename);
|
||||
success = file->open(Core::IODevice::OpenMode::ReadOnly);
|
||||
success = file->open(Core::OpenMode::ReadOnly);
|
||||
}
|
||||
if (!success) {
|
||||
fprintf(stderr, "Error: %s\n", file->error_string());
|
||||
|
|
|
@ -68,7 +68,7 @@ static bool mount_all()
|
|||
dbgln("Mounting all filesystems...");
|
||||
|
||||
auto fstab = Core::File::construct("/etc/fstab");
|
||||
if (!fstab->open(Core::IODevice::OpenMode::ReadOnly)) {
|
||||
if (!fstab->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Failed to open /etc/fstab: %s\n", fstab->error_string());
|
||||
return false;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ static bool print_mounts()
|
|||
{
|
||||
// Output info about currently mounted filesystems.
|
||||
auto df = Core::File::construct("/proc/df");
|
||||
if (!df->open(Core::IODevice::ReadOnly)) {
|
||||
if (!df->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Failed to open /proc/df: %s\n", df->error_string());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ int main()
|
|||
}
|
||||
|
||||
auto file = Core::File::construct("/proc/cpuinfo");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
perror("Core::File::open()");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ int main(int argc, char** argv)
|
|||
args_parser.parse(argc, argv);
|
||||
|
||||
auto file = Core::File::construct(String::formatted("/proc/{}/vm", pid));
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error: %s\n", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char** argv)
|
|||
files.append(Core::File::standard_input());
|
||||
} else {
|
||||
for (auto const& path : paths) {
|
||||
auto file_or_error = Core::File::open(path, Core::File::ReadOnly);
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, file_or_error.error());
|
||||
continue;
|
||||
|
|
|
@ -53,7 +53,7 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
auto file_or_error = Core::File::open(output_path, Core::IODevice::ReadWrite);
|
||||
auto file_or_error = Core::File::open(output_path, Core::OpenMode::ReadWrite);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Could not open '{}' for writing: {}", output_path, file_or_error.error());
|
||||
return 1;
|
||||
|
|
|
@ -52,7 +52,7 @@ int main(int argc, char** argv)
|
|||
parser.parse(argc, argv);
|
||||
|
||||
if (output_filename != nullptr) {
|
||||
auto open_result = Core::File::open(output_filename, Core::IODevice::OpenMode::WriteOnly);
|
||||
auto open_result = Core::File::open(output_filename, Core::OpenMode::WriteOnly);
|
||||
if (open_result.is_error()) {
|
||||
outln(stderr, "Failed to open output file: {}", open_result.error());
|
||||
return 1;
|
||||
|
|
|
@ -25,7 +25,7 @@ static String read_var(const String& name)
|
|||
builder.append(name);
|
||||
auto path = builder.to_string();
|
||||
auto f = Core::File::construct(path);
|
||||
if (!f->open(Core::IODevice::ReadOnly)) {
|
||||
if (!f->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "open: %s\n", f->error_string());
|
||||
exit(1);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ static void write_var(const String& name, const String& value)
|
|||
builder.append(name);
|
||||
auto path = builder.to_string();
|
||||
auto f = Core::File::construct(path);
|
||||
if (!f->open(Core::IODevice::WriteOnly)) {
|
||||
if (!f->open(Core::OpenMode::WriteOnly)) {
|
||||
fprintf(stderr, "open: %s\n", f->error_string());
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
|||
if (path == "-") {
|
||||
file = Core::File::standard_input();
|
||||
} else {
|
||||
auto file_or_error = Core::File::open(path, Core::File::ReadOnly);
|
||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Failed to open {}: {}", path, strerror(errno));
|
||||
continue;
|
||||
|
|
|
@ -94,7 +94,7 @@ int main(int argc, char* argv[])
|
|||
args_parser.parse(argc, argv);
|
||||
|
||||
auto f = Core::File::construct(file);
|
||||
if (!f->open(Core::IODevice::ReadOnly)) {
|
||||
if (!f->open(Core::OpenMode::ReadOnly)) {
|
||||
fprintf(stderr, "Error opening file %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc, char** argv)
|
|||
auto file = Core::File::standard_input();
|
||||
|
||||
if (archive_file) {
|
||||
auto maybe_file = Core::File::open(archive_file, Core::IODevice::OpenMode::ReadOnly);
|
||||
auto maybe_file = Core::File::open(archive_file, Core::OpenMode::ReadOnly);
|
||||
if (maybe_file.is_error()) {
|
||||
warnln("Core::File::open: {}", maybe_file.error());
|
||||
return 1;
|
||||
|
@ -120,7 +120,7 @@ int main(int argc, char** argv)
|
|||
auto file = Core::File::standard_output();
|
||||
|
||||
if (archive_file) {
|
||||
auto maybe_file = Core::File::open(archive_file, Core::IODevice::OpenMode::WriteOnly);
|
||||
auto maybe_file = Core::File::open(archive_file, Core::OpenMode::WriteOnly);
|
||||
if (maybe_file.is_error()) {
|
||||
warnln("Core::File::open: {}", maybe_file.error());
|
||||
return 1;
|
||||
|
@ -137,7 +137,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto add_file = [&](String path) {
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Failed to open {}: {}", path, file->error_string());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ static int run(Function<void(const char*, size_t)> fn)
|
|||
puts("File does not exist");
|
||||
return 1;
|
||||
}
|
||||
auto file = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly);
|
||||
auto file = Core::File::open(filename, Core::OpenMode::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
printf("That's a weird file man...\n");
|
||||
return 1;
|
||||
|
|
|
@ -141,7 +141,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto fn = parse_target_name(type);
|
||||
|
||||
auto file = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly);
|
||||
auto file = Core::File::open(filename, Core::OpenMode::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
warnln("Cannot read from file: {}", file.error());
|
||||
exit(1);
|
||||
|
|
|
@ -24,7 +24,7 @@ static bool unpack_zip_member(Archive::ZipMember zip_member)
|
|||
return true;
|
||||
}
|
||||
auto new_file = Core::File::construct(zip_member.name);
|
||||
if (!new_file->open(Core::IODevice::WriteOnly)) {
|
||||
if (!new_file->open(Core::OpenMode::WriteOnly)) {
|
||||
warnln("Can't write file {}: {}", zip_member.name, new_file->error_string());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc, char** argv)
|
|||
|
||||
dbgln("Updating utmp from UID={} GID={} EGID={} PID={}", getuid(), getgid(), getegid(), pid);
|
||||
|
||||
auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadWrite);
|
||||
auto file_or_error = Core::File::open("/var/run/utmp", Core::OpenMode::ReadWrite);
|
||||
if (file_or_error.is_error()) {
|
||||
dbgln("Error: {}", file_or_error.error());
|
||||
return 1;
|
||||
|
|
|
@ -45,7 +45,7 @@ int main()
|
|||
|
||||
unveil(nullptr, nullptr);
|
||||
|
||||
auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadOnly);
|
||||
auto file_or_error = Core::File::open("/var/run/utmp", Core::OpenMode::ReadOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
warnln("Error: {}", file_or_error.error());
|
||||
return 1;
|
||||
|
|
|
@ -17,7 +17,7 @@ int main(int argc, char* argv[])
|
|||
parser.add_positional_argument(filename, "File name to parse", "file");
|
||||
parser.parse(argc, argv);
|
||||
|
||||
auto result = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly);
|
||||
auto result = Core::File::open(filename, Core::OpenMode::ReadOnly);
|
||||
if (result.is_error()) {
|
||||
warnln("Failed to open {}: {}", filename, result.error());
|
||||
return 1;
|
||||
|
|
|
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto add_file = [&](String path) {
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
warnln("Failed to open {}: {}", path, file->error_string());
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue