From 9d34a1f4a70f25273012c7b520fbcb1b534c0f13 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 14 Sep 2022 16:26:53 +0100 Subject: [PATCH] md: Port to Core::Stream --- Userland/Utilities/md.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Userland/Utilities/md.cpp b/Userland/Utilities/md.cpp index 87dd3cb8870..1ae675bad90 100644 --- a/Userland/Utilities/md.cpp +++ b/Userland/Utilities/md.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -17,7 +17,7 @@ ErrorOr serenity_main(Main::Arguments arguments) { TRY(Core::System::pledge("stdio rpath tty")); - char const* filename = nullptr; + StringView filename; bool html = false; int view_width = 0; @@ -40,22 +40,12 @@ ErrorOr serenity_main(Main::Arguments arguments) view_width = 80; } } - auto file = Core::File::construct(); - bool success; - if (filename == nullptr) { - success = file->open(STDIN_FILENO, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No); - } else { - file->set_filename(filename); - success = file->open(Core::OpenMode::ReadOnly); - } - if (!success) { - warnln("Error: {}", file->error_string()); - return 1; - } + + auto file = TRY(Core::Stream::File::open_file_or_standard_stream(filename, Core::Stream::OpenMode::Read)); TRY(Core::System::pledge("stdio")); - auto buffer = file->read_all(); + auto buffer = TRY(file->read_all()); dbgln("Read size {}", buffer.size()); auto input = String::copy(buffer);