Changes the owner and group of a file. Format #include <unistd.h> int fchown (int fildes, uid_t owner, gid_t group);
1 – Arguments
fildes An open file descriptor. owner A user ID corresponding to the new owner of the file. group A group ID corresponding to the group of the file.
2 – Description
The fchown function has the same effect as chown except that the file whose owner and group are to be changed is specified by the file descriptor fildes.
3 – Return Values
0 Indicates success. -1 Indicates failure. The function sets errno to one of the following values: The fchown function will fail if: o EBADF - The fildes argument is not an open file descriptor. o EPERM - The effective user ID does not match the owner of the file, or the process does not have appropriate privilege. o EROFS - The file referred to by fildes resides on a read-only file system. The fchown function may fail if: o EINVAL - The owner or group ID is not a value supported by the implementation. o EIO - A physical I/O error has occurred. o EINTR - The fchown function was interrupted by a signal that was intercepted.