diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2021-11-27 16:51:46 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-11 15:10:42 -0800 |
commit | 6e066bf1cd27fb6eff48e4586c536f2f6dd8afe7 (patch) | |
tree | e392047bbb9270dd43c3d0ae56088bda28b9ca6d /Userland/Utilities | |
parent | 67a18d51c7be29e8382d16fd1300ac41becec105 (diff) | |
download | serenity-6e066bf1cd27fb6eff48e4586c536f2f6dd8afe7.zip |
cksum: Port to LibMain :^)
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Utilities/cksum.cpp | 17 |
2 files changed, 10 insertions, 9 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index 24f2af1d33..754320fbf7 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -67,7 +67,7 @@ target_link_libraries(chmod LibMain) target_link_libraries(chgrp LibMain) target_link_libraries(chown LibMain) target_link_libraries(chres LibGUI LibMain) -target_link_libraries(cksum LibCrypto) +target_link_libraries(cksum LibCrypto LibMain) target_link_libraries(config LibConfig) target_link_libraries(copy LibGUI LibMain) target_link_libraries(cp LibMain) diff --git a/Userland/Utilities/cksum.cpp b/Userland/Utilities/cksum.cpp index be7a6d3711..87807a94a7 100644 --- a/Userland/Utilities/cksum.cpp +++ b/Userland/Utilities/cksum.cpp @@ -8,9 +8,10 @@ #include <LibCore/File.h> #include <LibCrypto/Checksum/Adler32.h> #include <LibCrypto/Checksum/CRC32.h> +#include <LibMain/Main.h> #include <string.h> -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { Vector<const char*> paths; const char* opt_algorithm = nullptr; @@ -18,7 +19,7 @@ int main(int argc, char** argv) Core::ArgsParser args_parser; args_parser.add_option(opt_algorithm, "Checksum algorithm (default 'crc32', use 'list' to list available algorithms)", "algorithm", '\0', nullptr); args_parser.add_positional_argument(paths, "File", "file", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); + args_parser.parse(arguments); auto algorithm = (opt_algorithm == nullptr) ? "crc32" : String(opt_algorithm).to_lowercase(); @@ -33,7 +34,7 @@ int main(int argc, char** argv) } if (!available_algorithms.contains_slow(algorithm)) { - warnln("{}: Unknown checksum algorithm: {}", argv[0], algorithm); + warnln("{}: Unknown checksum algorithm: {}", arguments.strings[0], algorithm); exit(1); } @@ -45,13 +46,13 @@ int main(int argc, char** argv) auto filepath = (StringView(path) == "-") ? "/dev/stdin" : path; auto file = Core::File::construct(filepath); if (!file->open(Core::OpenMode::ReadOnly)) { - warnln("{}: {}: {}", argv[0], path, file->error_string()); + warnln("{}: {}: {}", arguments.strings[0], path, file->error_string()); fail = true; continue; } struct stat st; if (fstat(file->fd(), &st) < 0) { - warnln("{}: Failed to fstat {}: {}", argv[0], filepath, strerror(errno)); + warnln("{}: Failed to fstat {}: {}", arguments.strings[0], filepath, strerror(errno)); fail = true; continue; } @@ -60,7 +61,7 @@ int main(int argc, char** argv) while (!file->eof() && !file->has_error()) crc32.update(file->read(PAGE_SIZE)); if (file->has_error()) { - warnln("{}: Failed to read {}: {}", argv[0], filepath, file->error_string()); + warnln("{}: Failed to read {}: {}", arguments.strings[0], filepath, file->error_string()); fail = true; continue; } @@ -70,13 +71,13 @@ int main(int argc, char** argv) while (!file->eof() && !file->has_error()) adler32.update(file->read(PAGE_SIZE)); if (file->has_error()) { - warnln("{}: Failed to read {}: {}", argv[0], filepath, file->error_string()); + warnln("{}: Failed to read {}: {}", arguments.strings[0], filepath, file->error_string()); fail = true; continue; } outln("{:08x} {} {}", adler32.digest(), st.st_size, path); } else { - warnln("{}: Unknown checksum algorithm: {}", argv[0], algorithm); + warnln("{}: Unknown checksum algorithm: {}", arguments.strings[0], algorithm); exit(1); } } |