-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchmod.c
43 lines (31 loc) · 822 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
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
/*
Simulates the behavior of the 'chmod' command in Linux
Changes the permissions of a file or directory to the specified mode.
chmod filename 777
The first digit represents the owner's permissions.
The second digit represents the group's permissions.
The third digit represents others' (world) permissions.
Each digit can be a combination of the following values:
4 (read permission)
2 (write permission)
1 (execute permission)
0 (no permission)
*/
int main(int argc, char *argv[])
{
if (argc < 3)
{
printf("error\n");
return -1;
}
unsigned int mod = atoi(argv[2]);
if (chmod(argv[1], mod) != 0)
{
perror("Error");
return -1;
}
return 0;
}