CHOWN(2) — System Interface Manual — System Calls
NAME
chown − change owner and group of a file
SYNOPSIS
chown(path, owner, group)
char ∗path;
int owner, group;
fchown(fd, owner, group)
int fd, owner, group;
DESCRIPTION
The file which is named by path or referenced by fd has its owner and group changed as specified. Only the super-user may execute this call, because if users were able to give files away, they could defeat the (nonexistent) file-space accounting procedures.
On some systems, chown clears the set-user-id bit on the file to prevent accidental creation of set-user-id programs owned by the super-user.
Fchown is particularly useful when used in conjunction with the file locking primitives (see flock(2)).
Only one of the owner and group id’s may be set by specifying the other as −1.
RETURN VALUE
Zero is returned if the operation was successful; −1 is returned if an error occurs, with a more specific error code being placed in the global errno variable.
ERRORS
Chown will fail and the file will be unchanged if:
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The pathname was too long.
[EPERM] The path argument contained a byte with the high-order bit set.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied on a component of the path prefix.
[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.
[EFAULT] Path points outside the process’s valid address space.
[ELOOP] Too many symbolic links were encountered in translating the pathname.
Fchown will fail if:
[EBADF] Fd does not refer to a valid descriptor.
[EINVAL] Fd refers to a socket, not a file.
[EROFS] The file resides on a read-only file system.
SEE ALSO
Sun System Release 0.3 — 1 April 1983