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.\" @(#)link.2 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt LINK 2 10.Os BSD 4 11.Sh NAME 12.Nm link 13.Nd make a hard file link 14.Sh SYNOPSIS 15.Fd #include <unistd.h> 16.Ft int 17.Fn link "const char *name1" "const char *name2" 18.Sh DESCRIPTION 19The 20.Fn link 21function call 22atomically creates the specified directory entry (hard link) 23.Fa name2 24with the attributes of the underlying object pointed at by 25.Fa name1 26If the link is successful: the link count of the underlying object 27is incremented; 28.Fa name1 29and 30.Fa name2 31share equal access and rights 32to the 33underlying object. 34.Pp 35If 36.Fa name1 37is removed, the file 38.Fa name2 39is not deleted and the link count of the 40underlying object is 41decremented. 42.Pp 43.Fa Name1 44must exist for the hard link to 45succeed and 46both 47.Fa name1 48and 49.Fa name2 50must be in the same file system. 51Unless the caller is the super-user, 52.Fa name1 53may not be a directory. 54.Sh RETURN VALUES 55Upon successful completion, a value of 0 is returned. Otherwise, 56a value of -1 is returned and 57.Va errno 58is set to indicate the error. 59.Sh ERRORS 60.Fn Link 61will fail and no link will be created if: 62are true: 63.Bl -tag -width Ar 64.It Bq Er ENOTDIR 65A component of either path prefix is not a directory. 66.It Bq Er EINVAL 67Either pathname contains a character with the high-order bit set. 68.It Bq Er ENAMETOOLONG 69A component of either pathname exceeded 255 characters, 70or entire length of either path name exceeded 1023 characters. 71.It Bq Er ENOENT 72A component of either path prefix does not exist. 73.It Bq Er EACCES 74A component of either path prefix denies search permission. 75.It Bq Er EACCES 76The requested link requires writing in a directory with a mode 77that denies write permission. 78.It Bq Er ELOOP 79Too many symbolic links were encountered in translating one of the pathnames. 80.It Bq Er ENOENT 81The file named by 82.Fa name1 83does not exist. 84.It Bq Er EEXIST 85The link named by 86.Fa name2 87does exist. 88.It Bq Er EPERM 89The file named by 90.Fa name1 91is a directory and the effective 92user ID is not super-user. 93.It Bq Er EXDEV 94The link named by 95.Fa name2 96and the file named by 97.Fa name1 98are on different file systems. 99.It Bq Er ENOSPC 100The directory in which the entry for the new link is being placed 101cannot be extended because there is no space left on the file 102system containing the directory. 103.It Bq Er EDQUOT 104The directory in which the entry for the new link 105is being placed cannot be extended because the 106user's quota of disk blocks on the file system 107containing the directory has been exhausted. 108.It Bq Er EIO 109An I/O error occurred while reading from or writing to 110the file system to make the directory entry. 111.It Bq Er EROFS 112The requested link requires writing in a directory on a read-only file 113system. 114.It Bq Er EFAULT 115One of the pathnames specified 116is outside the process's allocated address space. 117.El 118.Sh SEE ALSO 119.Xr symlink 2 , 120.Xr unlink 2 121.Sh STANDARDS 122.Fn Link 123is expected to 124conform to IEEE Std 1003.1-1988 125.Pq Dq Tn POSIX . 126