k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit b244eb30373f3a5e82c511404f4b6725b604cad7
parent ea00641408b50b763f1d0a2d0d42ef225b554636
Author: qorg11 <qorg@vxempire.xyz>
Date:   Mon,  7 Sep 2020 17:59:18 +0200

added chgrp

Diffstat:
Asrc/chgrp.c | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/chgrp.c b/src/chgrp.c @@ -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)); + + } + +}