k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit 8eed6cca17f886ede7920eef1b98af0c784f961f
parent b244eb30373f3a5e82c511404f4b6725b604cad7
Author: qorg11 <qorg@vxempire.xyz>
Date:   Mon,  7 Sep 2020 21:29:14 +0200

added -h flag to chgrp

Diffstat:
Msrc/chgrp.c | 27++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)

diff --git 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)); + } } }