xref: /freebsd/lib/libsys/readlink.2 (revision 38b3683592d4c20a74f52a6e8e29368e6fa61858)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd March 30, 2020
29.Dt READLINK 2
30.Os
31.Sh NAME
32.Nm readlink ,
33.Nm readlinkat
34.Nd read value of a symbolic link
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In unistd.h
39.Ft ssize_t
40.Fn readlink "const char *restrict path" "char *restrict buf" "size_t bufsiz"
41.Ft ssize_t
42.Fo readlinkat
43.Fa "int fd" "const char *restrict path" "char *restrict buf" "size_t bufsize"
44.Fc
45.Sh DESCRIPTION
46The
47.Fn readlink
48system call
49places the contents of the symbolic link
50.Fa path
51in the buffer
52.Fa buf ,
53which has size
54.Fa bufsiz .
55The
56.Fn readlink
57system call does not append a
58.Dv NUL
59character to
60.Fa buf .
61.Pp
62The
63.Fn readlinkat
64system call is equivalent to
65.Fn readlink
66except in the case where
67.Fa path
68specifies a relative path.
69In this case the symbolic link whose content is read relative to the
70directory associated with the file descriptor
71.Fa fd
72instead of the current working directory.
73If
74.Fn readlinkat
75is passed the special value
76.Dv AT_FDCWD
77in the
78.Fa fd
79parameter, the current working directory is used and the behavior is
80identical to a call to
81.Fn readlink .
82.Sh RETURN VALUES
83The call returns the count of characters placed in the buffer
84if it succeeds, or a \-1 if an error occurs, placing the error
85code in the global variable
86.Va errno .
87.Sh ERRORS
88The
89.Fn readlink
90system call
91will fail if:
92.Bl -tag -width Er
93.It Bq Er ENOTDIR
94A component of the path prefix is not a directory.
95.It Bq Er ENAMETOOLONG
96A component of a pathname exceeded 255 characters,
97or an entire path name exceeded 1023 characters.
98.It Bq Er ENOENT
99The named file does not exist.
100.It Bq Er EACCES
101Search permission is denied for a component of the path prefix.
102.It Bq Er ELOOP
103Too many symbolic links were encountered in translating the pathname.
104.It Bq Er EINVAL
105The named file is not a symbolic link.
106.It Bq Er EIO
107An I/O error occurred while reading from the file system.
108.It Bq Er EINTEGRITY
109Corrupted data was detected while reading from the file system.
110.It Bq Er EFAULT
111The
112.Fa buf
113argument
114extends outside the process's allocated address space.
115.El
116.Pp
117In addition to the errors returned by the
118.Fn readlink ,
119the
120.Fn readlinkat
121may fail if:
122.Bl -tag -width Er
123.It Bq Er EBADF
124The
125.Fa path
126argument does not specify an absolute path and the
127.Fa fd
128argument is neither
129.Dv AT_FDCWD
130nor a valid file descriptor open for searching.
131.It Bq Er ENOTDIR
132The
133.Fa path
134argument is not an absolute path and
135.Fa fd
136is neither
137.Dv AT_FDCWD
138nor a file descriptor associated with a directory.
139.El
140.Sh SEE ALSO
141.Xr lstat 2 ,
142.Xr stat 2 ,
143.Xr symlink 2 ,
144.Xr symlink 7
145.Sh STANDARDS
146The
147.Fn readlinkat
148system call follows The Open Group Extended API Set 2 specification.
149.Sh HISTORY
150The
151.Fn readlink
152system call appeared in
153.Bx 4.2 .
154The
155.Fn readlinkat
156system call appeared in
157.Fx 8.0 .
158