a somewhat vague outline

This commit is contained in:
Gitea 2020-12-12 10:31:21 -06:00
parent 5bb1bf93a0
commit 3f10d08ddb
1 changed files with 25 additions and 2 deletions

27
chgrp.c
View File

@ -1,13 +1,18 @@
#define _POSIX_C_SOURCE 200809L
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
int chgrp_dir(char *, int);
int main(int argc, char * argv[]) {
char c;
int recurse = 0; /* -R */
/* 0: -P, 01: -L, 02: -H */
int recurse_follow = 0;
int follow_link = 0; /* -h */
int no_follow_link = 0; /* -h */
gid_t group;
while((c = getopt(argc, argv, "RHLPh")) != -1) {
switch(c) {
@ -15,7 +20,25 @@ int main(int argc, char * argv[]) {
case 'P': recurse_follow = 0; break;
case 'L': recurse_follow = 01; break;
case 'H': recurse_follow = 02; break;
case 'h': follow_link = 1; break;
case 'h': no_follow_link = 1; break;
}
}
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) {
}