0

Hey;

I'm trying to change the mode of a file in Linux system.

I know I must use chmod(const char* path, mode_t mode) but I don't really know how to handle the mode. How can I manipulate mode_t variable to apply my own mode?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by thierrypin
0

I don't really know how to handle the mode. How can I manipulate mode_t variable to apply my own mode?

mode_t is simply an unsigned int. chmod checks its last 9 bits. Each 3 bits are for read, write, execute. The first three are for user, then for group and last for everyone else.

e.g.: If I want to allow "rwx------", id make mode be like [... 1 1 1 0 0 0 0 0 0]. This way:

mode = 256|128|64.

If you want to make it allow everything for everyone, you do:

mode = 256|128|64|32....

or simply:

511
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.