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?
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?
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
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.