diff options
[SP/P03] Solved exercises
1 files changed, 16 insertions, 0 deletions
| -rw-r--r-- | Year 3/System programming/Practice03/ex2.c | 16 |
diff --git a/Year 3/System programming/Practice03/ex2.c b/Year 3/System programming/Practice03/ex2.c new file mode 100644 index 0000000..4b67c11 --- /dev/null +++ b/Year 3/System programming/Practice03/ex2.c @@ -0,0 +1,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; + } + } +} |
