mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
chgrp: Port to LibMain :^)
This commit is contained in:
parent
52a451dcff
commit
c8080fc2ca
2 changed files with 7 additions and 13 deletions
|
@ -64,6 +64,7 @@ target_link_libraries(cal LibMain)
|
||||||
target_link_libraries(cat LibMain)
|
target_link_libraries(cat LibMain)
|
||||||
target_link_libraries(checksum LibCrypto LibMain)
|
target_link_libraries(checksum LibCrypto LibMain)
|
||||||
target_link_libraries(chmod LibMain)
|
target_link_libraries(chmod LibMain)
|
||||||
|
target_link_libraries(chgrp LibMain)
|
||||||
target_link_libraries(chres LibGUI)
|
target_link_libraries(chres LibGUI)
|
||||||
target_link_libraries(cksum LibCrypto)
|
target_link_libraries(cksum LibCrypto)
|
||||||
target_link_libraries(config LibConfig)
|
target_link_libraries(config LibConfig)
|
||||||
|
|
|
@ -6,17 +6,14 @@
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.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) {
|
TRY(Core::System::pledge("stdio rpath chown", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* gid_arg = nullptr;
|
const char* gid_arg = nullptr;
|
||||||
const char* path = 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.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(gid_arg, "Group ID", "gid");
|
||||||
args_parser.add_positional_argument(path, "Path to file", "path");
|
args_parser.add_positional_argument(path, "Path to file", "path");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
gid_t new_gid = -1;
|
gid_t new_gid = -1;
|
||||||
|
|
||||||
|
@ -46,11 +43,7 @@ int main(int argc, char** argv)
|
||||||
new_gid = group->gr_gid;
|
new_gid = group->gr_gid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = chown(path, -1, new_gid);
|
TRY(Core::System::chown(path, -1, new_gid));
|
||||||
if (rc < 0) {
|
|
||||||
perror("chgrp");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue