FENIX_coreutils/chgrp.c

44 lines
953 B
C
Raw Normal View History

2020-12-12 07:58:36 +00:00
#define _POSIX_C_SOURCE 200809L
#include <unistd.h>
2020-12-12 16:31:21 +00:00
#include <sys/types.h>
#include <stdlib.h>
int chgrp_dir(char *, int);
2020-12-12 07:58:36 +00:00
int main(int argc, char * argv[]) {
char c;
int recurse = 0; /* -R */
/* 0: -P, 01: -L, 02: -H */
int recurse_follow = 0;
2020-12-12 16:31:21 +00:00
int no_follow_link = 0; /* -h */
gid_t group;
2020-12-12 07:58:36 +00:00
while((c = getopt(argc, argv, "RHLPh")) != -1) {
switch(c) {
case 'R': recurse = 1; break;
case 'P': recurse_follow = 0; break;
case 'L': recurse_follow = 01; break;
case 'H': recurse_follow = 02; break;
2020-12-12 16:31:21 +00:00
case 'h': no_follow_link = 1; break;
2020-12-12 07:58:36 +00:00
}
}
2020-12-12 16:31:21 +00:00
group = atoi(argv[optind++]);
for(; optind < argc; optind++) {
if(/* is a directory && */ recurse != 0) {
chgrp_dir(argv[optind], recurse_follow);
}
else if(no_follow_link != 0) {
chown(argv[optind], -1, group);
}
else {
chown(argv[optind], -1, group);
}
}
}
int chgrp_dir(char * path, int recurse_mode) {
2020-12-12 07:58:36 +00:00
}