-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchmod.c
30 lines (24 loc) · 841 Bytes
/
chmod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
#include<fcntl.h>
#include<stdlib.h>
int chmod(char *path, mode_t mode);
int main(){
int permission_status, new_permission_value;
char filepath[100];
// Taking the Input from the user
printf("Enter the filename with path: ");
scanf("%[^\n]%*c", filepath);
printf("Enter the new permission set: ");
// Permission Set value starts with 0.
// Eg: if i want to set 444 to a particular file then i need to give like 0444.
scanf("%d", &new_permission_value);
// Setting the Permissions
permission_status = chmod(filepath, new_permission_value);
// 0 ---> On Success || -1 ---> On Failure.
if (permission_status == 0){
printf("New permissions are Setted Successfully.!\n");
}else{
printf("Permissions Changed Sucessfully\n");
}
return 0;
}