Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

lchown - change owner/group of file

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

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

Description

The lchown() function sets the owner and the group affiliation of the specified file. This isthe same as chown() unless the file consists of a symbolic link. In this case lchown() changes the ownership of the link file, whereas chown() changes the ownership of the file or directory to which the link refers.

If chown(), lchown() or fchown() is called by a process that does not have system administrator status, the bit for setting the user and group IDs on execution, or S_ISUID and S_ISGID, is deleted [see chmod()].

The operating system has the configuration option _POSIX_CHOWN_RESTRICTED to prevent affiliation changes for chown(), lchown() and fchown() system calls. In POSIX, _POSIX_CHOWN_RESTRICTED is active, therefore the chown(), lchown() and fchown() system calls protect the owner of a file from having the owner IDs of his/her files changed, and they restrict the group change of the file to the list of supplementary group IDs.

After successful completion, chown(), lchown() and fchown() mark the ST_CTIME field of the file for update.

Return val.

0

if successful.


-1

if an error occurs. errno is set to indicate the error. If -1 is returned, the user ID and group ID of the file are not changed.

Errors

lchown() will fail if:

 

EACCES

Search permission is denied for a component of path.

 

EINVAL

The value of the specified user ID or group ID is not supported, e.g. if the value is less than 0, or an attempt was made to access a BS2000 file.

 

ENAMETOOLONG 



The length of the pathname exceeds {PATH_MAX}, or the length of a component of the pathname exceeds {NAME_MAX}.

 

ENOENT

A component of the pathname does not exist, or path points to an empty string.

 

ENOTDIR

A component of the pathname prefix is not a directory.

 

EOPNOTSUPP

The path argument identifies a symbolic link and the implementation does not support changing the owner or the group affiliation of a symbolic link.


ELOOP

Too many symbolic links were encountered in resolving path.


EPERM

The effective user ID does not match the owner of the file, and the calling process does not have the appropriate access permissions.


EROFS

The file is resides on a read-only file system.


EIO

An I/O error occurred while reading from or writing to the file system.


EINTR

A signal was caught during execution of the function.

 

Extension
ENAMETOOLONG 



The resolution of symbolic links in the pathname leads to an interim result whose length exceeds {PATH_MAX}. (End)

See also

chmod(), chown(), symlink(), unistd.h.