diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2021-11-27 15:24:25 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-11 15:10:42 -0800 |
commit | c8080fc2ca9185570a7d61935b0f28beb2184f50 (patch) | |
tree | 3c0a27d8809cb38e2b86e1172e0c538bb1bed6d0 /Userland/Utilities | |
parent | 52a451dcff3207df693b3571d48a0d875a5d241d (diff) | |
download | serenity-c8080fc2ca9185570a7d61935b0f28beb2184f50.zip |
chgrp: Port to LibMain :^)
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Utilities/chgrp.cpp | 19 |
2 files changed, 7 insertions, 13 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index c5a6f59b13..7454cceeb6 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -64,6 +64,7 @@ target_link_libraries(cal LibMain) target_link_libraries(cat LibMain) target_link_libraries(checksum LibCrypto LibMain) target_link_libraries(chmod LibMain) +target_link_libraries(chgrp LibMain) target_link_libraries(chres LibGUI) target_link_libraries(cksum LibCrypto) target_link_libraries(config LibConfig) diff --git a/Userland/Utilities/chgrp.cpp b/Userland/Utilities/chgrp.cpp index 69aba6b9fb..580febb215 100644 --- a/Userland/Utilities/chgrp.cpp +++ b/Userland/Utilities/chgrp.cpp @@ -6,17 +6,14 @@ #include <AK/String.h> #include <LibCore/ArgsParser.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <grp.h> -#include <stdio.h> #include <string.h> -#include <unistd.h> -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { - if (pledge("stdio rpath chown", nullptr) < 0) { - perror("pledge"); - return 1; - } + TRY(Core::System::pledge("stdio rpath chown", nullptr)); const char* gid_arg = nullptr; const char* path = nullptr; @@ -25,7 +22,7 @@ int main(int argc, char** argv) args_parser.set_general_help("Change the owning group for a file or directory."); args_parser.add_positional_argument(gid_arg, "Group ID", "gid"); args_parser.add_positional_argument(path, "Path to file", "path"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); gid_t new_gid = -1; @@ -46,11 +43,7 @@ int main(int argc, char** argv) new_gid = group->gr_gid; } - int rc = chown(path, -1, new_gid); - if (rc < 0) { - perror("chgrp"); - return 1; - } + TRY(Core::System::chown(path, -1, new_gid)); return 0; } |