chmod - change mode of a file
#include <sys/types.h> #include <sys/stat.h> int chmod(const char *path, mode_t mode);
The chmod() function changes S_ISUID, S_ISGID, S_ISVTX and the file permission bits of the file named by the pathname pointed to by the path argument to the corresponding bits in the mode argument. The effective user ID of the process must match the owner of the file or the process must have appropriate privileges in order to do this.
S_ISUID, S_ISGID and the file permission bits are described in <sys/stat.h>. behaviour is unspecified. will be cleared upon successful return from chmod().
Additional implementation-dependent restrictions may cause the S_ISUID and S_ISGID bits in mode to be ignored.
The effect on file descriptors for files open at the time of a call to chmod() is implementation-dependent.
Upon successful completion, chmod() will mark for update the st_ctime field of the file.
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. If -1 is returned, no change to the file mode will occur.
The chmod().
- [ENAMETOOLONG]
- Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
None.
In order to ensure that the S_ISUID and S_ISGID bits are set, an application requiring this should use stat() after a successful chmod() to verify this.
Any file descriptors currently open by any process on the file may become invalid if the mode of the file is changed to a value which would deny access to that process. One situation where this could occur is on a stateless file system.
None.
chown(), mkdir(), mkfifo(), open(), stat(), statvfs(), <sys/stat.h>, <sys/types.h>.
Derived from Issue 1 of the SVID.