Added chown.c

Please someone use strtok() to get the group

-R flag is needed as always
This commit is contained in:
qorg11 2020-06-15 14:41:29 +02:00
parent f4dc0887a9
commit 530bb5c584
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 28 additions and 0 deletions

28
src/chown.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
/* TODO: use strtok() to get the group */
int
main(int argc, char *argv[])
{
if(argc == 1)
{
fprintf(stderr,"No command given\n");
return 1;
}
const char *user = argv[1];
struct passwd *data = getpwnam(user);
uid_t uid = data->pw_gid;
gid_t gid = data->pw_gid; /* Change this with the strtok() thing */
for(int i = 2; i<=argc; i++)
{
chown(argv[i],uid,gid);
}
return 0;
}