1.\" $OpenBSD: readlink.2,v 1.19 2015/05/31 23:54:25 schwarze Exp $ 2.\" $NetBSD: readlink.2,v 1.7 1995/02/27 12:35:54 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.\" @(#)readlink.2 8.1 (Berkeley) 6/4/93 32.\" 33.Dd $Mdocdate: May 31 2015 $ 34.Dt READLINK 2 35.Os 36.Sh NAME 37.Nm readlink , 38.Nm readlinkat 39.Nd read value of a symbolic link 40.Sh SYNOPSIS 41.In unistd.h 42.Ft ssize_t 43.Fn readlink "const char *restrict path" "char *restrict buf" "size_t bufsiz" 44.In fcntl.h 45.In unistd.h 46.Ft ssize_t 47.Fn readlinkat "int fd" "const char *path" "char *buf" "size_t bufsiz" 48.Sh DESCRIPTION 49The 50.Fn readlink 51function places the contents of the symbolic link 52.Fa path 53in the buffer 54.Fa buf , 55which has size 56.Fa bufsiz . 57.Fn readlink 58does not append a 59.Dv NUL 60character to 61.Fa buf . 62.Pp 63The 64.Fn readlinkat 65function is equivalent to 66.Fn readlink 67except that where 68.Fa path 69specifies a relative path, 70the symbolic link whose contents are read is determined relative to 71the directory associated with file descriptor 72.Fa fd 73instead of the current working directory. 74.Pp 75If 76.Fn readlinkat 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 readlink . 86.Sh RETURN VALUES 87The call returns the count of characters placed in the buffer 88if it succeeds, or a \-1 if an error occurs, placing the error 89code in the global variable 90.Va errno . 91.Sh ERRORS 92.Fn readlink 93and 94.Fn readlinkat 95will fail if: 96.Bl -tag -width Er 97.It Bq Er ENOTDIR 98A component of the path prefix is not a directory. 99.It Bq Er ENAMETOOLONG 100A component of a pathname exceeded 101.Dv NAME_MAX 102characters, or an entire pathname (including the terminating NUL) 103exceeded 104.Dv PATH_MAX 105bytes. 106.It Bq Er ENOENT 107The named file does not exist. 108.It Bq Er EACCES 109Search permission is denied for a component of the path prefix. 110.It Bq Er ELOOP 111Too many symbolic links were encountered in translating the pathname. 112.It Bq Er EINVAL 113The named file is not a symbolic link. 114.It Bq Er EIO 115An I/O error occurred while reading from the file system. 116.It Bq Er EFAULT 117.Fa buf 118or 119.Fa path 120extends outside the process's allocated address space. 121.El 122.Pp 123Additionally, 124.Fn readlinkat 125will fail if: 126.Bl -tag -width Er 127.It Bq Er EBADF 128The 129.Fa path 130argument specifies a relative path and the 131.Fa fd 132argument is neither 133.Dv AT_FDCWD 134nor a valid file descriptor. 135.It Bq Er ENOTDIR 136The 137.Fa path 138argument specifies a relative path and the 139.Fa fd 140argument is a valid file descriptor but it does not reference a directory. 141.It Bq Er EACCES 142The 143.Fa path 144argument specifies a relative path but search permission is denied 145for the directory which the 146.Fa fd 147file descriptor references. 148.El 149.Sh SEE ALSO 150.Xr lstat 2 , 151.Xr stat 2 , 152.Xr symlink 2 , 153.Xr symlink 7 154.Sh STANDARDS 155The 156.Fn readlink 157and 158.Fn readlinkat 159functions conform to 160.St -p1003.1-2008 . 161.Sh HISTORY 162The 163.Fn readlink 164system call first appeared in 165.Bx 4.1c . 166The 167.Fn readlinkat 168system call has been available since 169.Ox 5.0 . 170