added chgrp

This commit is contained in:
qorg11 2020-09-07 17:59:18 +02:00
parent ea00641408
commit b244eb3037
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 24 additions and 0 deletions

24
src/chgrp.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <unistd.h>
#include <grp.h>
#include <errno.h>
#include <string.h>
int
main(int argc, char *argv[])
{
if(argc == 1 || argc == 2)
{
fprintf(stderr,"usage: chgrp group file...\n");
return 1;
}
struct group *group_data = getgrnam(argv[1]);
gid_t gid = group_data->gr_gid;
for(int i = 2; i<argc; i++)
{
if(chown(argv[i],gid,getuid()) == -1)
fprintf(stderr,"error %i = %s\n",errno,strerror(errno));
}
}