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.
5 .\" @(#)chmod.2 6.5 (Berkeley) 5/13/86
7 .TH CHMOD 2 "May 13, 1986"
10 chmod, fchmod \- change mode of file
14 #include <sys/types.h>
17 int chmod(const char *\fIpath\fP, mode_t \fImode\fP)
21 int fchmod(int \fIfd\fP, mode_t \fImode\fP)
26 is given by \fIpath\fP
28 or referenced by the descriptor
31 has its mode changed to
33 Modes are constructed by
36 combination of the following, defined in
41 .ta \w'S_ISUID\ \ 'u +\w'04000\ \ \ 'u
42 S_ISUID 04000 set user ID on execution
43 S_ISGID 02000 set group ID on execution
44 S_ISVTX 01000 `sticky bit' (see below)
45 S_IRWXU 00700 read, write, execute by owner
46 S_IRUSR 00400 read by owner
47 S_IWUSR 00200 write by owner
48 S_IXUSR 00100 execute (search on directory) by owner
49 S_IRWXG 00070 read, write, execute by group
50 S_IRGRP 00040 read by group
51 S_IWGRP 00020 write by group
52 S_IXGRP 00010 execute (search on directory) by group
53 S_IRWXO 00007 read, write, execute by others
54 S_IROTH 00004 read by others
55 S_IWOTH 00002 write by others
56 S_IXOTH 00001 execute (search on directory) by others
60 If mode ISVTX (the `sticky bit') is set on a directory,
61 an unprivileged user may not delete or rename
62 files of other users in that directory. (Minix-vmd)
64 Only the owner of a file (or the super-user) may change the mode.
66 Writing or changing the owner of a file
67 turns off the set-user-id and set-group-id bits
68 unless the user is the super-user.
69 This makes the system somewhat more secure
70 by protecting set-user-id (set-group-id) files
71 from remaining set-user-id (set-group-id) if they are modified,
72 at the expense of a degree of compatibility.
74 Upon successful completion, a value of 0 is returned.
75 Otherwise, a value of \-1 is returned and
77 is set to indicate the error.
80 will fail and the file mode will be unchanged if:
83 A component of the path prefix is not a directory.
86 The path name exceeds PATH_MAX characters.
89 The named file does not exist.
92 Search permission is denied for a component of the path prefix.
95 Too many symbolic links were encountered in translating the pathname.
99 The effective user ID does not match the owner of the file and
100 the effective user ID is not the super-user.
103 The named file resides on a read-only file system.
107 points outside the process's allocated address space.
110 An I/O error occurred while reading from or writing to the file system.
117 The descriptor is not valid.
120 The file resides on a read-only file system.
123 An I/O error occurred while reading from or writing to the file system.
131 The sticky bit was historically used to lock important executables into