mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
checksum: Port to LibMain :^)
This commit is contained in:
parent
6b6d7286b5
commit
59d299955e
2 changed files with 9 additions and 10 deletions
|
@ -62,7 +62,7 @@ target_link_libraries(bt LibSymbolication LibMain)
|
||||||
target_link_libraries(blockdev LibMain)
|
target_link_libraries(blockdev LibMain)
|
||||||
target_link_libraries(cal LibMain)
|
target_link_libraries(cal LibMain)
|
||||||
target_link_libraries(cat LibMain)
|
target_link_libraries(cat LibMain)
|
||||||
target_link_libraries(checksum LibCrypto)
|
target_link_libraries(checksum LibCrypto LibMain)
|
||||||
target_link_libraries(chmod LibMain)
|
target_link_libraries(chmod LibMain)
|
||||||
target_link_libraries(chres LibGUI)
|
target_link_libraries(chres LibGUI)
|
||||||
target_link_libraries(cksum LibCrypto)
|
target_link_libraries(cksum LibCrypto)
|
||||||
|
|
|
@ -6,17 +6,16 @@
|
||||||
|
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <LibCrypto/Hash/HashManager.h>
|
#include <LibCrypto/Hash/HashManager.h>
|
||||||
|
#include <LibMain/Main.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto program_name = StringView { argv[0] };
|
auto program_name = arguments.strings[0];
|
||||||
auto hash_kind = Crypto::Hash::HashKind::None;
|
auto hash_kind = Crypto::Hash::HashKind::None;
|
||||||
|
|
||||||
if (program_name == "md5sum")
|
if (program_name == "md5sum")
|
||||||
|
@ -29,7 +28,7 @@ int main(int argc, char** argv)
|
||||||
hash_kind = Crypto::Hash::HashKind::SHA512;
|
hash_kind = Crypto::Hash::HashKind::SHA512;
|
||||||
|
|
||||||
if (hash_kind == Crypto::Hash::HashKind::None) {
|
if (hash_kind == Crypto::Hash::HashKind::None) {
|
||||||
warnln("Error: program must be executed as 'md5sum', 'sha1sum', 'sha256sum' or 'sha512sum'; got '{}'", argv[0]);
|
warnln("Error: program must be executed as 'md5sum', 'sha1sum', 'sha256sum' or 'sha512sum'; got '{}'", program_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(paths, paths_help_string.characters(), "path", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(paths, paths_help_string.characters(), "path", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
if (paths.is_empty())
|
if (paths.is_empty())
|
||||||
paths.append("-");
|
paths.append("-");
|
||||||
|
@ -55,7 +54,7 @@ int main(int argc, char** argv)
|
||||||
if (path != "-"sv) {
|
if (path != "-"sv) {
|
||||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||||
if (file_or_error.is_error()) {
|
if (file_or_error.is_error()) {
|
||||||
warnln("{}: {}: {}", argv[0], path, file->error_string());
|
warnln("{}: {}: {}", program_name, path, file->error_string());
|
||||||
has_error = true;
|
has_error = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue