chgrp: Port to LibMain :^)

This commit is contained in:
Kenneth Myhra 2021-11-27 15:24:25 +01:00 committed by Brian Gianforcaro
parent 52a451dcff
commit c8080fc2ca
Notes: sideshowbarker 2024-07-17 22:56:52 +09:00
2 changed files with 7 additions and 13 deletions

View file

@ -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)

View file

@ -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;
}