CHOWN(2)
NAME
chown − change owner or group of a file
USAGE
chown(path, owner, group) char *path; int owner, group;
fchown(fd, owner, group) int fd, owner, group;
DESCRIPTION
Chown (fchown) sets the owner and group of the object specified by path (or file descriptor fd). Only the super-user may execute this call.
On some systems, chown clears the set-user-ID and set-group-ID bits on the file to prevent accidental creation of set-user-ID and set-group-ID programs owned by the super-user.
Fchown is particularly useful when used in conjunction with the file-locking primitives (see flock(2)).
You may set either the owner or the group ID without changing the other. Set the ID you do not want to change to -1.
RETURN VALUE
A successful call returns zero. A failed call returns -1 and sets errno as indicated below.
ERRORS
Chown will fail and the file will be unchanged if:
[EINVAL] The argument path does not refer to a file.
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The argument pathname is too long.
[EPERM] The argument contains 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 allocated address space.
[ELOOP] The call encountered too many symbolic links 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.