mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
base64: Port to LibMain
This commit is contained in:
parent
f47d92af72
commit
b918e798e6
2 changed files with 8 additions and 10 deletions
|
@ -54,6 +54,7 @@ endforeach()
|
||||||
target_link_libraries(aplay LibAudio)
|
target_link_libraries(aplay LibAudio)
|
||||||
target_link_libraries(arp LibMain)
|
target_link_libraries(arp LibMain)
|
||||||
target_link_libraries(asctl LibAudio)
|
target_link_libraries(asctl LibAudio)
|
||||||
|
target_link_libraries(base64 LibMain)
|
||||||
target_link_libraries(bt LibSymbolication)
|
target_link_libraries(bt LibSymbolication)
|
||||||
target_link_libraries(checksum LibCrypto)
|
target_link_libraries(checksum LibCrypto)
|
||||||
target_link_libraries(chres LibGUI)
|
target_link_libraries(chres LibGUI)
|
||||||
|
|
|
@ -9,16 +9,15 @@
|
||||||
#include <AK/ByteBuffer.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 <LibMain/Main.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool decode = false;
|
bool decode = false;
|
||||||
const char* filepath = nullptr;
|
const char* filepath = nullptr;
|
||||||
|
@ -26,7 +25,7 @@ int main(int argc, char** argv)
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(decode, "Decode data", "decode", 'd');
|
args_parser.add_option(decode, "Decode data", "decode", 'd');
|
||||||
args_parser.add_positional_argument(filepath, "", "file", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(filepath, "", "file", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
ByteBuffer buffer;
|
ByteBuffer buffer;
|
||||||
if (filepath == nullptr || strcmp(filepath, "-") == 0) {
|
if (filepath == nullptr || strcmp(filepath, "-") == 0) {
|
||||||
|
@ -44,10 +43,7 @@ int main(int argc, char** argv)
|
||||||
buffer = file->read_all();
|
buffer = file->read_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pledge("stdio", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decode) {
|
if (decode) {
|
||||||
auto decoded = decode_base64(StringView(buffer));
|
auto decoded = decode_base64(StringView(buffer));
|
||||||
|
@ -61,4 +57,5 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto encoded = encode_base64(buffer);
|
auto encoded = encode_base64(buffer);
|
||||||
outln("{}", encoded);
|
outln("{}", encoded);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue