mirror of https://git.qorg11.net/k9core.git
added -h flag to chgrp
This commit is contained in:
parent
b244eb3037
commit
8eed6cca17
27
src/chgrp.c
27
src/chgrp.c
|
@ -7,18 +7,35 @@
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int follow_symlink;
|
||||
while((c = getopt(argc,argv,"h")) != -1 )
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'h': follow_symlink = 1; break;
|
||||
}
|
||||
}
|
||||
if(argc == 1 || argc == 2)
|
||||
{
|
||||
fprintf(stderr,"usage: chgrp group file...\n");
|
||||
return 1;
|
||||
}
|
||||
struct group *group_data = getgrnam(argv[1]);
|
||||
struct group *group_data = getgrnam(argv[optind
|
||||
]);
|
||||
gid_t gid = group_data->gr_gid;
|
||||
for(int i = 2; i<argc; i++)
|
||||
for(int i = optind+1; i<argc; i++)
|
||||
{
|
||||
if(chown(argv[i],gid,getuid()) == -1)
|
||||
fprintf(stderr,"error %i = %s\n",errno,strerror(errno));
|
||||
|
||||
if(follow_symlink)
|
||||
{
|
||||
if(lchown(argv[i],gid,getuid()) == -1)
|
||||
fprintf(stderr,"Error: %i = %s\n",errno,strerror(errno));
|
||||
}
|
||||
else
|
||||
if(chown(argv[i],gid,getuid()) == -1)
|
||||
{
|
||||
fprintf(stderr,"Error: %i = %s\n",errno,strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue