RFS | XFS

chown()

PROTOTYPE

#include <posix.h>

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

DESCRIPTION

chown() optionally sets the user and group IDs of the file specified by path. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD. If user is not (uid_t)-1, it becomes the file’s new user ID. If group is not (gid_t)-1, it becomes the file’s new group ID.

The caller must own the file and have execute access to every directory in the path prefix. If either ID is changed, the file’s status change timestamp is updated.

If successful, chown() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No execute access to a directory in the path prefix.
EFAULT path equals NULL.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a file that was not found.
ENOTDIR One of the non-leaf path components is not a directory.
EPERM The caller is not the file’s owner (per FsGetId()).
EROFS The volume is read-only.

EXAMPLE

/*---------------------------------------------------------------*/
/* Change file's group ID to the privileged group.               */
/*---------------------------------------------------------------*/
if (chown(path, (uid_t)-1, PrivGp))
{
  perror("chown() failed");
  return -1;
}