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.3 (Berkeley) 01/12/94 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: 62.Bl -tag -width Ar 63.It Bq Er ENOTDIR 64A component of either path prefix is not a directory. 65.It Bq Er EINVAL 66Either pathname contains a character with the high-order bit set. 67.It Bq Er ENAMETOOLONG 68A component of either pathname exceeded 255 characters, 69or entire length of either path name exceeded 1023 characters. 70.It Bq Er ENOENT 71A component of either path prefix does not exist. 72.It Bq Er EACCES 73A component of either path prefix denies search permission. 74.It Bq Er EACCES 75The requested link requires writing in a directory with a mode 76that denies write permission. 77.It Bq Er ELOOP 78Too many symbolic links were encountered in translating one of the pathnames. 79.It Bq Er ENOENT 80The file named by 81.Fa name1 82does not exist. 83.It Bq Er EEXIST 84The link named by 85.Fa name2 86does exist. 87.It Bq Er EPERM 88The file named by 89.Fa name1 90is a directory and the effective 91user ID is not super-user. 92.It Bq Er EXDEV 93The link named by 94.Fa name2 95and the file named by 96.Fa name1 97are on different file systems. 98.It Bq Er ENOSPC 99The directory in which the entry for the new link is being placed 100cannot be extended because there is no space left on the file 101system containing the directory. 102.ne 3v 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