1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)chown.2 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt CHOWN 2 10.Os BSD 4 11.Sh NAME 12.Nm chown , 13.Nm fchown 14.Nd change owner and group of a file 15.Sh SYNOPSIS 16.Fd #include <unistd.h> 17.Ft int 18.Fn chown "const char *path" "uid_t owner" "gid_t group" 19.Ft int 20.Fn fchown "int fd" "uid_t owner" "uid_t group" 21.Sh DESCRIPTION 22The owner ID and group ID of the file 23named by 24.Fa path 25or referenced by 26.Fa fd 27is changed as specified by the arguments 28.Fa owner 29and 30.Fa group . 31The owner of a file may change the 32.Fa group 33to a group of which 34he or she is a member, 35but the change 36.Fa owner 37capability is restricted to the super-user. 38.Pp 39.Fn Chown 40clears the set-user-id and set-group-id bits 41on the file 42to prevent accidental or mischievious creation of 43set-user-id and set-group-id programs. 44.Pp 45.Fn Fchown 46is particularly useful when used in conjunction 47with the file locking primitives (see 48.Xr flock 2 ) . 49.Pp 50One of the owner or group id's 51may be left unchanged by specifying it as -1. 52.Pp 53If the final component of 54.Fa path 55is a symbolic link, 56the ownership and group of the symbolic link is changed, 57not the ownership and group of the file or directory to which it points. 58.Sh RETURN VALUES 59Zero is returned if the operation was successful; 60-1 is returned if an error occurs, with a more specific 61error code being placed in the global variable 62.Va errno . 63.Sh ERRORS 64.Fn Chown 65will fail and the file will be unchanged if: 66.Bl -tag -width Er 67.It Bq Er ENOTDIR 68A component of the path prefix is not a directory. 69.It Bq Er EINVAL 70The pathname contains a character with the high-order bit set. 71.It Bq Er ENAMETOOLONG 72A component of a pathname exceeded 255 characters, 73or an entire path name exceeded 1023 characters. 74.It Bq Er ENOENT 75The named file does not exist. 76.It Bq Er EACCES 77Search permission is denied for a component of the path prefix. 78.It Bq Er ELOOP 79Too many symbolic links were encountered in translating the pathname. 80.It Bq Er EPERM 81The effective user ID is not the super-user. 82.It Bq Er EROFS 83The named file resides on a read-only file system. 84.It Bq Er EFAULT 85.Fa Path 86points outside the process's allocated address space. 87.It Bq Er EIO 88An I/O error occurred while reading from or writing to the file system. 89.El 90.Pp 91.Fn Fchown 92will fail if: 93.Bl -tag -width Er 94.It Bq Er EBADF 95.Fa Fd 96does not refer to a valid descriptor. 97.It Bq Er EINVAL 98.Fa Fd 99refers to a socket, not a file. 100.It Bq Er EPERM 101The effective user ID is not the super-user. 102.It Bq Er EROFS 103The named file resides on a read-only file system. 104.It Bq Er EIO 105An I/O error occurred while reading from or writing to the file system. 106.El 107.Sh SEE ALSO 108.Xr chown 8 , 109.Xr chgrp 1 , 110.Xr chmod 2 , 111.Xr flock 2 112.Sh STANDARDS 113.Fn Chown 114is expected to conform to IEEE Std 1003.1-1988 115.Pq Dq Tn POSIX . 116.Sh HISTORY 117The 118.Fn fchown 119function call 120appeared in 121.Bx 4.2 . 122