improved english
[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.\"
86ce3f09 5.\" @(#)chmod.2 6.3 (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
KM
31together some
32combination of the following:
33.PP
34.RS
35 04000 set user ID on execution
36 02000 set group ID on execution
37 01000 save text image after execution
38 00400 read by owner
39 00200 write by owner
40 00100 execute (search on directory) by owner
41 00070 read, write, execute (search) by group
42 00007 read, write, execute (search) by others
43.RE
44.PP
45If an executable file is set up for sharing (this is the default)
46then mode 1000 prevents the system from
47abandoning the swap-space image of the program-text portion
48of the file when its last user
49terminates.
7656e522 50Ability to set this bit is restricted to the super-user.
d149e2aa
KM
51.PP
52Only the owner of a file (or the super-user) may change the mode.
d149e2aa 53.PP
7656e522
KM
54Writing or changing the owner of a file
55turns off the set-user-id and set-group-id bits.
d149e2aa 56This makes the system somewhat more secure
7656e522
KM
57by protecting set-user-id (set-group-id) files
58from remaining set-user-id (set-group-id) if they are modified,
d149e2aa 59at the expense of a degree of compatibility.
7656e522
KM
60.SH "RETURN VALUE
61Upon successful completion, a value of 0 is returned.
62Otherwise, a value of \-1 is returned and
63.I errno
64is set to indicate the error.
65.SH "ERRORS
66.I Chmod
67will fail and the file mode will be unchanged if:
68.TP 15
7656e522
KM
69[ENOTDIR]
70A component of the path prefix is not a directory.
71.TP 15
b5984ffe
KM
72[EINVAL]
73The pathname contains a character with the high-order bit set.
74.TP 15
75[ENAMETOOLONG]
76A component of a pathname exceeded 255 characters,
77or an entire path name exceeded 1023 characters.
7656e522
KM
78.TP 15
79[ENOENT]
80The named file does not exist.
81.TP 15
82[EACCES]
b5984ffe
KM
83Search permission is denied for a component of the path prefix.
84.TP 15
85[ELOOP]
86Too many symbolic links were encountered in translating the pathname.
7656e522
KM
87.TP 15
88[EPERM]
89The effective user ID does not match the owner of the file and
90the effective user ID is not the super-user.
91.TP 15
92[EROFS]
93The named file resides on a read-only file system.
94.TP 15
95[EFAULT]
96.I Path
97points outside the process's allocated address space.
7656e522
KM
98.PP
99.I Fchmod
100will fail if:
101.TP 15
102[EBADF]
103The descriptor is not valid.
104.TP 15
105[EINVAL]
106.I Fd
107refers to a socket, not to a file.
108.TP 15
109[EROFS]
110The file resides on a read-only file system.
d149e2aa 111.SH "SEE ALSO"
7656e522 112open(2), chown(2)