update error messages (mostly from sun!guy)
[unix-history] / usr / src / lib / libc / sys / chown.2
CommitLineData
37512f15
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.\"
fd690c8b 5.\" @(#)chown.2 6.4 (Berkeley) %G%
37512f15 6.\"
9a68374b 7.TH CHOWN 2 ""
37512f15
KM
8.UC 4
9.SH NAME
10chown \- change owner and group of a file
11.SH SYNOPSIS
12.nf
0aa506e6
KM
13.ft B
14chown(path, owner, group)
15char *path;
16int owner, group;
17.PP
18.ft B
19fchown(fd, owner, group)
20int fd, owner, group;
37512f15
KM
21.fi
22.SH DESCRIPTION
23The file
d84f45ef 24that is named by \fIpath\fP or referenced by \fIfd\fP
37512f15
KM
25has its
26.I owner
27and
28.I group
29changed as specified.
30Only the super-user may
31execute this call,
32because if users were able to give files away,
0aa506e6 33they could defeat the file-space accounting procedures.
37512f15
KM
34.PP
35On some systems,
36.I chown
0aa506e6 37clears the set-user-id and set-group-id bits
37512f15
KM
38on the file
39to prevent accidental creation of
0aa506e6
KM
40set-user-id and set-group-id programs
41owned by the super-user.
42.PP
43.I Fchown
44is particularly useful when used in conjunction
45with the file locking primitives (see
46.IR flock (2)).
47.PP
48Only one of the owner and group id's
49may be set by specifying the other as \-1.
50.SH "RETURN VALUE
51Zero is returned if the operation was successful;
52\-1 is returned if an error occurs, with a more specific
53error code being placed in the global variable \fIerrno\fP.
54.SH "ERRORS
55.I Chown
56will fail and the file will be unchanged if:
57.TP 15
0aa506e6
KM
58[ENOTDIR]
59A component of the path prefix is not a directory.
60.TP 15
b5984ffe
KM
61[EINVAL]
62The pathname contains a character with the high-order bit set.
0aa506e6 63.TP 15
b5984ffe
KM
64[ENAMETOOLONG]
65A component of a pathname exceeded 255 characters,
66or an entire path name exceeded 1023 characters.
0aa506e6
KM
67.TP 15
68[ENOENT]
69The named file does not exist.
70.TP 15
71[EACCES]
b5984ffe
KM
72Search permission is denied for a component of the path prefix.
73.TP 15
74[ELOOP]
75Too many symbolic links were encountered in translating the pathname.
0aa506e6
KM
76.TP 15
77[EPERM]
fd690c8b 78The effective user ID is not the super-user.
0aa506e6
KM
79.TP 15
80[EROFS]
81The named file resides on a read-only file system.
82.TP 15
83[EFAULT]
84.I Path
85points outside the process's allocated address space.
fd690c8b
KM
86.TP 15
87[EIO]
88An I/O error occurred while reading from or writing to the file system.
0aa506e6
KM
89.PP
90.I Fchown
91will fail if:
92.TP 15
93[EBADF]
94.I Fd
95does not refer to a valid descriptor.
96.TP 15
97[EINVAL]
98.I Fd
99refers to a socket, not a file.
b5984ffe 100.TP 15
fd690c8b
KM
101[EPERM]
102The effective user ID is not the super-user.
103.TP 15
b5984ffe
KM
104[EROFS]
105The named file resides on a read-only file system.
fd690c8b
KM
106.TP 15
107[EIO]
108An I/O error occurred while reading from or writing to the file system.
37512f15 109.SH "SEE ALSO"
0aa506e6 110chmod(2), flock(2)