chmod(), fchmod() - change mode of file
#include <sys/stat.h>
int chmod (const char *path, mode_t mode)
int fchmod (int fildes, mode_t mode)
The function chmod(2) sets the file permission bits of the file specified by the pathname path to mode. The fchmod(2) does the same, except that the file is specified by the file descriptor filedes.
Chmod(2) and fchmod(2) verify that the process owner (user) owns the file specified by path. A mode is created from OR'd permission bit masks defined in <sys/stat.h>:
Symbol | Value | Meaning |
---|---|---|
S_IRWXU | 0000700 | RWX mask for owner |
S_IRUSR | 0000400 | R for owner |
S_IWUSR | 0000200 | W for owner |
S_IXUSR | 0000100 | X for owner |
S_IRWXG | 0000070 | RWX mask for group |
S_IRGRP | 0000040 | R for group |
S_IWGRP | 0000020 | W for group |
S_IXGRP | 0000010 | X for group |
S_IRWXO | 0000007 | RWX mask for other |
S_IROTH | 0000004 | R for other |
S_IWOTH | 0000002 | W for other |
S_IXOTH | 0000001 | X for other |
S_ISUID | 0004000 | set user ID on execution; see NOTES later in this topic |
S_ISGID | 0002000 | set group ID on execution; see NOTES later in this topic |
Calling the chmod(2) function on a file with open file descriptors has no effect on the open file descriptors.
Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error.
The chmod(2) function will fail and the file mode will be unchanged if:
The fchmod(2) function can fail for the following reasons:
When you use chmod(2) or fchmod(2) to make a file writeable, the function will unset the Win32 Read-Only attribute, if it is set on the file. (If the Read-Only attribute is set, the stat(2) function will report that the file is not writeable, regardless of the permissions on the ACLs associated with the file.)
By default, Interix does not execute files with the set-user-ID (setuid) or set-group-ID (setgid) mode bit set for security reasons. If an attempt is made to execute such a file, the ENOSETUID error is returned. For more information and and instructions for enabling execution of files with these mode bits set, see The superuser account and appropriate privileges in Windows Services for UNIX Help.
chmod(1)
open(2)
chown(2)
stat(2)
privileges(5)