aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2020-09-07 21:29:14 +0200
committerqorg11 <qorg@vxempire.xyz>2020-09-07 21:29:14 +0200
commit8eed6cca17f886ede7920eef1b98af0c784f961f (patch)
tree2d134d68119b8c854e6dd4afe38708cd5d8382cf
parentb244eb30373f3a5e82c511404f4b6725b604cad7 (diff)
downloadk9core-8eed6cca17f886ede7920eef1b98af0c784f961f.tar.gz
k9core-8eed6cca17f886ede7920eef1b98af0c784f961f.zip
added -h flag to chgrp
-rw-r--r--src/chgrp.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/chgrp.c b/src/chgrp.c
index 75873a6..b0a7ddc 100644
--- a/src/chgrp.c
+++ b/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));
+ }
}
}