man.bsd.lv manual page server

Manual Page Search Parameters

CHOWN(2) System Calls Manual CHOWN(2)

chown, fchownchange owner and group of a file

#include <unistd.h>

int
chown(const char *path, uid_t owner, gid_t group);

int
fchown(int fd, uid_t owner, uid_t group);

The owner ID and group ID of the file named by path or referenced by fd is changed as specified by the arguments owner and group. The owner of a file may change the group to a group of which he or she is a member, but the change owner capability is restricted to the super-user.

() clears the set-user-id and set-group-id bits on the file to prevent accidental or mischievous creation of set-user-id and set-group-id programs.

() is particularly useful when used in conjunction with the file locking primitives (see flock(2)).

One of the owner or group id's may be left unchanged by specifying it as -1.

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 variable errno.

Chown() will fail and the file will be unchanged if:

[]
A component of the path prefix is not a directory.
[]
The pathname contains a character with the high-order bit set.
[]
A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.
[]
The named file does not exist.
[]
Search permission is denied for a component of the path prefix.
[]
Too many symbolic links were encountered in translating the pathname.
[]
The effective user ID is not the super-user.
[]
The named file resides on a read-only file system.
[]
Path points outside the process's allocated address space.
[]
An I/O error occurred while reading from or writing to the file system.

Fchown() will fail if:

[]
Fd does not refer to a valid descriptor.
[]
Fd refers to a socket, not a file.
[]
The effective user ID is not the super-user.
[]
The named file resides on a read-only file system.
[]
An I/O error occurred while reading from or writing to the file system.

chown(8), chgrp(1), chmod(2), flock(2)

Chown() is expected to conform to IEEE Std 1003.1-1988 (“POSIX”).

The fchown() function call appeared in 4.2BSD.

The chown() and fchown() functions were changed to follow symbolic links in 4.4BSD.

BSD 4 April 19, 1994 CHOWN(2)