mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
base64: Use Core::File standard_input() standard_output()
This commit is contained in:
parent
8ae492ba4d
commit
ec1f5fd20f
1 changed files with 2 additions and 12 deletions
|
@ -4,16 +4,12 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
|
||||||
#include <AK/Base64.h>
|
#include <AK/Base64.h>
|
||||||
#include <AK/ByteBuffer.h>
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
|
@ -29,13 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
ByteBuffer buffer;
|
ByteBuffer buffer;
|
||||||
if (filepath == nullptr || strcmp(filepath, "-") == 0) {
|
if (filepath == nullptr || strcmp(filepath, "-") == 0) {
|
||||||
auto file = Core::File::construct();
|
buffer = Core::File::standard_input()->read_all();
|
||||||
bool success = file->open(
|
|
||||||
STDIN_FILENO,
|
|
||||||
Core::OpenMode::ReadOnly,
|
|
||||||
Core::File::ShouldCloseFileDescriptor::Yes);
|
|
||||||
VERIFY(success);
|
|
||||||
buffer = file->read_all();
|
|
||||||
} else {
|
} else {
|
||||||
auto result = Core::File::open(filepath, Core::OpenMode::ReadOnly);
|
auto result = Core::File::open(filepath, Core::OpenMode::ReadOnly);
|
||||||
VERIFY(!result.is_error());
|
VERIFY(!result.is_error());
|
||||||
|
@ -47,7 +37,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
if (decode) {
|
if (decode) {
|
||||||
auto decoded = TRY(decode_base64(StringView(buffer)));
|
auto decoded = TRY(decode_base64(StringView(buffer)));
|
||||||
fwrite(decoded.data(), sizeof(u8), decoded.size(), stdout);
|
Core::File::standard_output()->write(decoded.data(), decoded.size());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue