CHMOD
Section: System Calls (2)
Updated: August 1, 1992
Index
Return to Main Contents
NAME
chmod - change mode of file
SYNOPSIS
int chmod(const char *path, mode_t mode);
int fchmod(int fd, int mode);
DESCRIPTION
The
chmod
function changes the mode of the file whose pathname is given by
path
according to the value of
mode.
The
fchmod
function changes the mode of the open file
given by file descriptor
fd.
Only a process whose effective user ID
matches the file owner or
is that of the super-user
can change the mode of a file.
The
mode
argument is
a bitwise inclusive OR combination
of the values described in
stat(2)
or
stat(2P).
Writing to a file always turns off the
set-user-id and set-group-id bits.
If an executable file is set up for sharing (this is the default)
then mode S_ISVTX (the `sticky bit') prevents the system from
abandoning the swap-space image of the program-text portion
of the file when its last user terminates.
Ability to set this bit on executable files is restricted to the super-user.
If mode S_ISVTX (the `sticky bit') is set on a directory,
an unprivileged user may not delete or rename
files of other users in that directory.
For more details of the properties of the sticky bit, see
sticky(8).
Upon successful completion,
chmod
marks for update the
st_ctime
field of the file.
RETURN VALUE
Upon successful completion,
chmod
returns a value of zero.
Otherwise, a value of -1 is returned and
errno
is set to indicate the error.
ERRORS
If any of the following conditions occurs,
chmod
returns -1 and sets
errno
to the corresponding value:
- [EACCES]
-
Search permission is denied for a component of the path prefix.
- [EFAULT]
-
The
path
argument points outside the process's allocated address space.
- [EINVAL]
-
The pathname contains a character with the high-order bit set.
- [EIO]
-
An I/O error occurred while reading from or writing to the file system.
- [ELOOP]
-
Too many symbolic links were encountered in translating the pathname.
- [ENAMETOOLONG]
-
A component of
path
exceeds 255 characters,
or the entire pathname exceeds 1023 characters.
For POSIX applications these values are given
by the constants {NAME_MAX} and {PATH_MAX}, respectively.
- [ENOTDIR]
-
A component of the path prefix is not a directory.
- [ENOENT]
-
The named file does not exist or
path
points to an empty string.
- [EPERM]
-
The effective user ID does not match the owner of the file and
the effective user ID is not the super-user.
- [EROFS]
-
The named file resides on a read-only file system.
The following errors cause
Fchmod
to fail and return -1:
- [EBADF]
-
The descriptor is not valid.
- [EINVAL]
-
Fd
refers to a socket, not to a file.
- [EIO]
-
An I/O error occurred while reading from or writing to the file system.
- [EROFS]
-
The file resides on a read-only file system.
SEE ALSO
chmod(1),
chown(2),
mkdir(2),
mkfifo(2P),
open(2),
stat(2) or stat(2P),
sticky(8)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUE
-
- ERRORS
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 00:59:11 GMT, September 26, 2024