Implementation status: to be implemented

Synopsis

#include <sys/stat.h>

int chmod(const char *path, mode_t mode);

#include <fcntl.h>

int fchmodat(int fd, const char *path, mode_t mode, int flag);

Description

The chmod() function modifies file mode bits according to the the mode parameter.

fchmodat function is equivalent to chmod() unless the path is a relative path.
The file to be changed is determined then relative to the directory associated with the file descriptor fd instead of the current working directory. If the access mode of the open file description associated with the file descriptor is not O_SEARCH, the function checks whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. If the access mode is O_SEARCH, the function does not perform the check.

Values for flag are constructed by a bitwise-inclusive OR of the following flags (<fcntl.h>) :

  • AT_SYMLINK_NOFOLLOW - if path names a symbolic link, then the mode of the symbolic link is changed.
  • AT_FDCWD - for this value of the fd parameter of fchmodat() the current working directory is used. If also flag is zero, the behavior shall be identical to that of chmod().

Arguments:
path - a pointer to the file path.
mode - a required file mode bit sequence.

fd - a file descriptor of the directory.
flag - flags defining the function behavior as mentioned above.

Return value

On success the functions return 0and otherwise they return -1 and set the errno value .

Errors

[EACCES] - search permission is denied on a component of the path prefix or the access mode of the open file description associated with fd is not O_SEARCH and the permissions of the directory underlying fd do not permit directory searches.
[ELOOP] - a loop exists in symbolic links encountered during resolution of the path argument.
[ENAMETOOLONG] - the length of a component of a pathname is longer than {NAME_MAX}.
[ENOENT] - a component of path does not name an existing file or path is an empty string.
[ENOTDIR] - a component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory, or the path argument contains at least one non- character and ends with one or more trailing characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory.
[EPERM] - the effective user ID does not match the owner of the file and the process does not have appropriate privileges.
[EROFS] - the named file resides on a read-only file system.
[EBADF] - the path argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor open for reading or searching.
[ENOTDIR] - the path argument is not an absolute path and fd is a file descriptor associated with a non-directory file.
[EINTR] - a signal was caught during execution of the function.
[EINVAL] - the value of the mode argument is invalid or the value of the flag argument is invalid..
[ELOOP] - more than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument.
[ENAMETOOLONG] - the length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.
[EOPNOTSUPP] - the AT_SYMLINK_NOFOLLOW bit is set in the flag argument, path names a symbolic link, and the system does not support changing the mode of a symbolic link.