chown(2) CLIX chown(2)
NAME
chown - Changes the owner and group ID of a file
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <sys/types.h>
int chown(
char *path ,
uid_t owner ,
gid_t group );
PARAMETERS
path Points to the name of the file for which the owner ID and group ID
are to be changed.
owner Specifies the numeric value representing the owner ID.
group Specifies the numeric value representing the group ID.
DESCRIPTION
The path parameter points to a pathname naming a file. The owner ID and
group ID of the named file are set to the numeric values contained in
owner and group respectively.
Only processes with effective user ID equal to the file owner or superuser
may change the ownership of a file. If _POSIX_CHOWN_RESTRICTED (see the
sysconfig command) is in effect:
⊕ Changing the owner is restricted to processes with appropriate
privileges.
⊕ Changing the group is permitted to a process with an effective user ID
equal to the user ID of the file, but without appropriate privileges,
if and only if owner is equal to the file user ID and group is equal
either to the calling process' effective group ID or to one of its
supplementary group IDs.
If the chown() function is invoked by other than the superuser, the set-
user-ID and set-group-ID bits of the file mode, 04000 and 02000
respectively, will be cleared.
EXAMPLES
2/94 - Intergraph Corporation 1
chown(2) CLIX chown(2)
To change the owner ID and group ID of a file to user ID 0:
if (!chown("filename", 0, 0))
perror("Could not chown filename");
RETURN VALUES
Upon successful completion, chown() returns a value of 0. Otherwise, a
value of -1 is returned and the global variable errno is set to indicate
the error.
ERRORS
The chown() function fails and the owner and group of the named file will
remain unchanged if one or more of the following are true:
[ENOTDIR]
A component of the path prefix is not a directory.
[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 superuser.
[ENAMETOOLONG]
The length of the path parameter exceeds PATH_MAX, or a pathname
component is longer than NAME_MAX while _POSIX_NO_TRUNC (see
master.d) is in effect.
[EROFS]
The named file resides on a read-only file system.
[EFAULT]
The path parameter points outside the allocated address space of
the process.
[EINTR]
A signal was caught during the chown() function.
[ENOLINK]
The path parameter points to a remote machine and the link to that
machine is no longer active.
[EMULTIHOP]
Components of path require hopping to multiple remote machines.
2 Intergraph Corporation - 2/94
chown(2) CLIX chown(2)
RELATED INFORMATION
Commands: chown(1), sysconfig(8)
Functions: chmod(2)
2/94 - Intergraph Corporation 3