Try to fix SIGIO problem with Sun machines, h_errno with
[unix-history] / usr / src / lib / libc / sys / chmod.2
CommitLineData
d149e2aa
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
ed77f7df 5.\" @(#)chmod.2 6.5 (Berkeley) %G%
d149e2aa 6.\"
3efa6125 7.TH CHMOD 2 ""
d149e2aa
KM
8.UC 4
9.SH NAME
10chmod \- change mode of file
11.SH SYNOPSIS
12.nf
7656e522
KM
13.ft B
14chmod(path, mode)
15char *path;
16int mode;
17.PP
18.ft B
19fchmod(fd, mode)
20int fd, mode;
d149e2aa
KM
21.fi
22.SH DESCRIPTION
23The file whose name
7656e522
KM
24is given by \fIpath\fP
25or referenced by the descriptor
26.I fd
d149e2aa
KM
27has its mode changed to
28.IR mode .
29Modes are constructed by
7656e522 30.IR or 'ing
d149e2aa 31together some
ed77f7df
MK
32combination of the following, defined in
33.IR <sys/inode.h> :
d149e2aa
KM
34.PP
35.RS
ed77f7df
MK
36.nf
37.ta \w'IWRITE\ \ 'u +\w'04000\ \ \ 'u
38ISUID 04000 set user ID on execution
39ISGID 02000 set group ID on execution
40ISVTX 01000 `sticky bit' (see below)
41IREAD 00400 read by owner
42IWRITE 00200 write by owner
43IEXEC 00100 execute (search on directory) by owner
44 00070 read, write, execute (search) by group
45 00007 read, write, execute (search) by others
46.fi
d149e2aa
KM
47.RE
48.PP
49If an executable file is set up for sharing (this is the default)
ed77f7df 50then mode ISVTX (the `sticky bit') prevents the system from
d149e2aa 51abandoning the swap-space image of the program-text portion
31d564b9
DS
52of the file when its last user terminates.
53Ability to set this bit on executable files is restricted to the super-user.
54.PP
ed77f7df 55If mode ISVTX (the `sticky bit') is set on a directory,
31d564b9
DS
56an unprivileged user may not delete or rename
57files of other users in that directory.
58For more details of the properties of the sticky bit, see
59.IR sticky (8).
d149e2aa
KM
60.PP
61Only the owner of a file (or the super-user) may change the mode.
d149e2aa 62.PP
7656e522 63Writing or changing the owner of a file
ed77f7df
MK
64turns off the set-user-id and set-group-id bits
65unless the user is the super-user.
d149e2aa 66This makes the system somewhat more secure
7656e522
KM
67by protecting set-user-id (set-group-id) files
68from remaining set-user-id (set-group-id) if they are modified,
d149e2aa 69at the expense of a degree of compatibility.
7656e522
KM
70.SH "RETURN VALUE
71Upon successful completion, a value of 0 is returned.
72Otherwise, a value of \-1 is returned and
73.I errno
74is set to indicate the error.
75.SH "ERRORS
76.I Chmod
77will fail and the file mode will be unchanged if:
78.TP 15
7656e522
KM
79[ENOTDIR]
80A component of the path prefix is not a directory.
81.TP 15
b5984ffe
KM
82[EINVAL]
83The pathname contains a character with the high-order bit set.
84.TP 15
85[ENAMETOOLONG]
86A component of a pathname exceeded 255 characters,
87or an entire path name exceeded 1023 characters.
7656e522
KM
88.TP 15
89[ENOENT]
90The named file does not exist.
91.TP 15
92[EACCES]
b5984ffe
KM
93Search permission is denied for a component of the path prefix.
94.TP 15
95[ELOOP]
96Too many symbolic links were encountered in translating the pathname.
7656e522
KM
97.TP 15
98[EPERM]
99The effective user ID does not match the owner of the file and
100the effective user ID is not the super-user.
101.TP 15
102[EROFS]
103The named file resides on a read-only file system.
104.TP 15
105[EFAULT]
106.I Path
107points outside the process's allocated address space.
fd690c8b
KM
108.TP 15
109[EIO]
110An I/O error occurred while reading from or writing to the file system.
7656e522
KM
111.PP
112.I Fchmod
113will fail if:
114.TP 15
115[EBADF]
116The descriptor is not valid.
117.TP 15
118[EINVAL]
119.I Fd
120refers to a socket, not to a file.
121.TP 15
122[EROFS]
123The file resides on a read-only file system.
fd690c8b
KM
124.TP 15
125[EIO]
126An I/O error occurred while reading from or writing to the file system.
d149e2aa 127.SH "SEE ALSO"
31d564b9 128chmod(1), open(2), chown(2), stat(2), sticky(8)