From 39a4f1560b8a81b238cfb7a402adbf9c3c1678d4 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 13 Sep 2022 22:02:20 +0100 Subject: [PATCH] copy: Port to Core::Stream --- Userland/Utilities/copy.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Userland/Utilities/copy.cpp b/Userland/Utilities/copy.cpp index 3186ccd979..f366934fa9 100644 --- a/Userland/Utilities/copy.cpp +++ b/Userland/Utilities/copy.cpp @@ -9,8 +9,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -22,7 +21,7 @@ struct Options { bool clear; }; -static Options parse_options(Main::Arguments arguments) +static ErrorOr parse_options(Main::Arguments arguments) { auto type = "text/plain"sv; Vector text; @@ -43,15 +42,11 @@ static Options parse_options(Main::Arguments arguments) // We're not copying anything. } else if (text.is_empty()) { // Copy our stdin. - auto c_stdin = Core::File::construct(); - bool success = c_stdin->open( - STDIN_FILENO, - Core::OpenMode::ReadOnly, - Core::File::ShouldCloseFileDescriptor::No); - VERIFY(success); - auto buffer = c_stdin->read_all(); + auto c_stdin = TRY(Core::Stream::File::standard_input()); + auto buffer = TRY(c_stdin->read_all()); dbgln("Read size {}", buffer.size()); - options.data = String((char*)buffer.data(), buffer.size()); + dbgln("Read data: `{}`", StringView(buffer.bytes())); + options.data = buffer.bytes(); } else { // Copy the rest of our command-line args. StringBuilder builder; @@ -66,7 +61,7 @@ ErrorOr serenity_main(Main::Arguments arguments) { auto app = TRY(GUI::Application::try_create(arguments)); - Options options = parse_options(arguments); + Options options = TRY(parse_options(arguments)); auto& clipboard = GUI::Clipboard::the(); if (options.clear)