Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / System programming / Practice03 / ex2.c
blob: 4b67c1139a0ff0a4953c4ceec521afcfb1a52cd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <sys/stat.h>
#include <stdio.h> // perror

int main(int argc, char* argv[]) {
	for (int i = 1; i < argc; i++) {
		struct stat buf;
		if(stat(argv[i], &buf) < 0) {
			perror("stat");
			return 1;
		}
		if (chmod(argv[i], (buf.st_mode | S_IWGRP) & ~S_IXOTH) < 0) {
			perror("chmod");
			return 2;
		}
	}
}