CHOWN(2) BSD CHOWN(2)
NAME
chown, fchown - change owner and group of a file
SYNOPSIS
#include <sys/types.h>
chown(path, owner, group)
const char *path;
uid_t owner;
gid_t group;
fchown(fd, owner, group)
int fd;
uid_t owner;
gid_t group;
DESCRIPTION
chown changes the owner and group of the file named by path or referenced
by fd as specified. Only the super-user may change the owner of the file
because, if users were able to give files away, they could defeat the
file-space accounting procedures. The owner of the file can change the
group to a group of which he is a member.
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, unless the
caller's real set-user-id or identity is ROOT.
fchown is particularly useful when used in conjunction with the file
locking primitives (see flock(2)).
One of the owner or group IDs may be left unchanged by specifying it as
-1.
Under some implementations, if the final component of path is a symbolic
link, the ownership and group of the symbolic link is changed, not the
ownership and group of the file or directory to which it points. Links
under Domain/OS BSD don't have owners or groups; this operation always
returns success.
There is no effect on open file descriptors at the time of the chown or
fchown.
ERRORS
chown will fail and the file will be unchanged if any of the following
are true.
[ENOTDIR] A component of the path prefix is not a directory.
[ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
entire pathname exceeded 1023 characters.
[ENOENT] The named file does not exist or path points to an empty
string.
[EACCES] Search permission is denied for a component of the path
prefix.
[ELOOP] Too many symbolic links were encountered in translating
the pathname.
[EROFS] The named file resides on a read-only file system.
[EIO] An I/O error occurred while reading from or writing to
the file system.
[EINVAL] The owner or group ID supplied is not a supported value.
fchown will fail if any of the following are true:
[EBADF] fd does not refer to a valid descriptor.
[EINVAL] fd refers to a socket, not a file.
[EROFS] The named file resides on a read-only file system.
[EIO] An I/O error occurred while reading from or writing to
the file system.
chown and fchown also return the following error:
[EPERM] Someone with the user ID other than super-user is
attempting to change the file's owner or thr files's
group to a group of which he is not a member.
SEE ALSO
chown(8), chgrp(1), chmod(2), flock(2)
DIAGNOSTICS
A successful call returns 0. An unsuccessful call returns -1 and sets
errno.
NOTES
In some implementations, chown may also return the following error:
[EINVAL] The pathname contains a character with the high-order
bit set.