1.\" $OpenBSD: symlink.2,v 1.16 2013/07/17 05:42:11 schwarze Exp $ 2.\" $NetBSD: symlink.2,v 1.7 1995/02/27 12:38:34 cgd Exp $ 3.\" 4.\" Copyright (c) 1983, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)symlink.2 8.1 (Berkeley) 6/4/93 32.\" 33.Dd $Mdocdate: July 17 2013 $ 34.Dt SYMLINK 2 35.Os 36.Sh NAME 37.Nm symlink 38.Nd make symbolic link to a file 39.Sh SYNOPSIS 40.Fd #include <unistd.h> 41.Ft int 42.Fn symlink "const char *name1" "const char *name2" 43.Fd #include <fcntl.h> 44.Fd #include <unistd.h> 45.Ft int 46.Fn symlinkat "const char *name1" "int fd" "const char *name2" 47.Sh DESCRIPTION 48A symbolic link 49.Fa name2 50is created to 51.Fa name1 52.Pf ( Fa name2 53is the name of the 54file created, 55.Fa name1 56is the string 57used in creating the symbolic link). 58Either name may be an arbitrary path name; the files need not 59be on the same file system, and the file specified by 60.Fa name1 61need not exist at all. 62.Pp 63The 64.Fn symlinkat 65function is equivalent to 66.Fn symlink 67except that where 68.Fa name2 69specifies a relative path, 70the newly created symbolic link is created relative to 71the directory associated with file descriptor 72.Fa fd 73instead of the current working directory. 74.Pp 75If 76.Fn symlinkat 77is passed the special value 78.Dv AT_FDCWD 79(defined in 80.In fcntl.h ) 81in the 82.Fa fd 83parameter, the current working directory is used 84and the behavior is identical to a call to 85.Fn symlink . 86.Sh RETURN VALUES 87Upon successful completion, a zero value is returned. 88If an error occurs, the error code is stored in 89.Va errno 90and a \-1 value is returned. 91.Sh ERRORS 92The symbolic link succeeds unless: 93.Bl -tag -width Er 94.It Bq Er ENOTDIR 95A component of the 96.Fa name2 97prefix is not a directory. 98.It Bq Er ENAMETOOLONG 99A component of a pathname exceeded 100.Dv {NAME_MAX} 101characters, or an entire path name exceeded 102.Dv {PATH_MAX} 103characters. 104.It Bq Er ENOENT 105The named file does not exist. 106.It Bq Er EACCES 107A component of the 108.Fa name2 109path prefix denies search permission. 110.It Bq Er ELOOP 111Too many symbolic links were encountered in translating the pathname. 112.It Bq Er EEXIST 113.Fa name2 114already exists. 115.It Bq Er EIO 116An I/O error occurred while making the directory entry for 117.Fa name2 , 118or allocating the inode for 119.Fa name2 , 120or writing out the link contents of 121.Fa name2 . 122.It Bq Er EROFS 123The file 124.Fa name2 125would reside on a read-only file system. 126.It Bq Er ENOSPC 127The directory in which the entry for the new symbolic link is being placed 128cannot be extended because there is no space left on the file 129system containing the directory. 130.It Bq Er ENOSPC 131The new symbolic link cannot be created because there 132is no space left on the file 133system that will contain the symbolic link. 134.It Bq Er ENOSPC 135There are no free inodes on the file system on which the 136symbolic link is being created. 137.It Bq Er EDQUOT 138The directory in which the entry for the new symbolic link 139is being placed cannot be extended because the 140user's quota of disk blocks on the file system 141containing the directory has been exhausted. 142.It Bq Er EDQUOT 143The new symbolic link cannot be created because the user's 144quota of disk blocks on the file system that will 145contain the symbolic link has been exhausted. 146.It Bq Er EDQUOT 147The user's quota of inodes on the file system on 148which the symbolic link is being created has been exhausted. 149.It Bq Er EIO 150An I/O error occurred while making the directory entry or allocating the inode. 151.It Bq Er EFAULT 152.Fa name1 153or 154.Fa name2 155points outside the process's allocated address space. 156.El 157.Pp 158Additionally, 159.Fn symlinkat 160will fail if: 161.Bl -tag -width Er 162.It Bq Er EBADF 163The 164.Fa name2 165argument specifies a relative path and the 166.Fa fd 167argument is neither 168.Dv AT_FDCWD 169nor a valid file descriptor. 170.It Bq Er ENOTDIR 171The 172.Fa name2 173argument specifies a relative path and the 174.Fa fd 175argument is a valid file descriptor but it does not reference a directory. 176.It Bq Er EACCES 177The 178.Fa name2 179argument specifies a relative path but search permission is denied 180for the directory which the 181.Fa fd 182file descriptor references. 183.El 184.Sh SEE ALSO 185.Xr ln 1 , 186.Xr link 2 , 187.Xr readlink 2 , 188.Xr unlink 2 , 189.Xr symlink 7 190.Sh STANDARDS 191The 192.Fn symlink 193and 194.Fn symlinkat 195functions conform to 196.St -p1003.1-2008 . 197.Sh HISTORY 198The 199.Fn symlink 200system call first appeared in 201.Bx 4.1c . 202The 203.Fn symlinkat 204system call has been available since 205.Ox 5.0 . 206