md: Port to Core::Stream

This commit is contained in:
Sam Atkins 2022-09-14 16:26:53 +01:00 committed by Linus Groh
parent 14ce07dd52
commit 9d34a1f4a7
Notes: sideshowbarker 2024-07-17 04:15:53 +09:00

View File

@ -6,7 +6,7 @@
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <LibMarkdown/Document.h>
@ -17,7 +17,7 @@ ErrorOr<int> 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<int> 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);