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.2 (Berkeley) 12/30/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.Sh RETURN VALUES 53Zero is returned if the operation was successful; 54-1 is returned if an error occurs, with a more specific 55error code being placed in the global variable 56.Va errno . 57.Sh ERRORS 58.Fn Chown 59will fail and the file will be unchanged if: 60.Bl -tag -width Er 61.It Bq Er ENOTDIR 62A component of the path prefix is not a directory. 63.It Bq Er EINVAL 64The pathname contains a character with the high-order bit set. 65.It Bq Er ENAMETOOLONG 66A component of a pathname exceeded 255 characters, 67or an entire path name exceeded 1023 characters. 68.It Bq Er ENOENT 69The named file does not exist. 70.It Bq Er EACCES 71Search permission is denied for a component of the path prefix. 72.It Bq Er ELOOP 73Too many symbolic links were encountered in translating the pathname. 74.It Bq Er EPERM 75The effective user ID is not the super-user. 76.It Bq Er EROFS 77The named file resides on a read-only file system. 78.It Bq Er EFAULT 79.Fa Path 80points outside the process's allocated address space. 81.It Bq Er EIO 82An I/O error occurred while reading from or writing to the file system. 83.El 84.Pp 85.Fn Fchown 86will fail if: 87.Bl -tag -width Er 88.It Bq Er EBADF 89.Fa Fd 90does not refer to a valid descriptor. 91.It Bq Er EINVAL 92.Fa Fd 93refers to a socket, not a file. 94.It Bq Er EPERM 95The effective user ID is not the super-user. 96.It Bq Er EROFS 97The named file resides on a read-only file system. 98.It Bq Er EIO 99An I/O error occurred while reading from or writing to the file system. 100.El 101.Sh SEE ALSO 102.Xr chown 8 , 103.Xr chgrp 1 , 104.Xr chmod 2 , 105.Xr flock 2 106.Sh STANDARDS 107.Fn Chown 108is expected to conform to IEEE Std 1003.1-1988 109.Pq Dq Tn POSIX . 110.Sh HISTORY 111The 112.Fn fchown 113function call 114appeared in 115.Bx 4.2 . 116