xref: /xnu-11417.140.69/bsd/man/man2/readlink.2 (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1.\"	$NetBSD: readlink.2,v 1.7 1995/02/27 12:35:54 cgd Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)readlink.2	8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt READLINK 2
38.Os BSD 4.2
39.Sh NAME
40.Nm readlink ,
41.Nm readlinkat ,
42.Nm freadlink
43.Nd read value of a symbolic link
44.Sh SYNOPSIS
45.Fd #include <unistd.h>
46.Ft  ssize_t
47.Fo readlink
48.Fa "const char *restrict path"
49.Fa "char *restrict buf"
50.Fa "size_t bufsize"
51.Fc
52.Ft ssize_t
53.Fo readlinkat
54.Fa "int fd" "const char *restrict path" "char *restrict buf" "size_t bufsize"
55.Fc
56.Ft ssize_t
57.Fo freadlink
58.Fa "int fd" "char *restrict buf" "size_t bufsize"
59.Fc
60.Sh DESCRIPTION
61.Fn readlink
62places the contents of the symbolic link
63.Fa path
64in the buffer
65.Fa buf ,
66which has size
67.Fa bufsize .
68.Nm Readlink
69does not append a
70.Dv NUL
71character to
72.Fa buf .
73.Pp
74The
75.Fn readlinkat
76system call is equivalent to
77.Fn readlink
78except in the case where
79.Fa path
80specifies a relative path.
81In this case the symbolic link whose content is read relative to the
82directory associated with the file descriptor
83.Fa fd
84instead of the current working directory.
85If
86.Fn readlinkat
87is passed the special value
88.Dv AT_FDCWD
89in the
90.Fa fd
91parameter, the current working directory is used and the behavior is
92identical to a call to
93.Fn readlink .
94The
95.Fn freadlink
96system call returns the same information about an open symbolic link file referenced by descriptor
97.Fa fd .
98.Sh RETURN VALUES
99The call returns the count of characters placed in the buffer
100if it succeeds, or a -1 if an error occurs, placing the error
101code in the global variable
102.Va errno .
103.Sh ERRORS
104.Fn readlink
105will fail if:
106.Bl -tag -width Er
107.\" ===========
108.It Bq Er EACCES
109Search permission is denied for a component of the path prefix.
110.\" ===========
111.It Bq Er EFAULT
112.Fa Buf
113extends outside the process's allocated address space.
114.\" ===========
115.It Bq Er EINVAL
116The named file is not a symbolic link.
117.\" ===========
118.It Bq Er EIO
119An I/O error occurred while reading from the file system.
120.\" ===========
121.It Bq Er ELOOP
122Too many symbolic links are encountered in translating the pathname.
123This is taken to be indicative of a looping symbolic link.
124.\" ===========
125.It Bq Er ENAMETOOLONG
126A component of a pathname exceeded
127.Dv {NAME_MAX}
128characters, or an entire path name
129(possibly expanded by a symbolic link) exceeded
130.Dv {PATH_MAX}
131characters.
132.\" ===========
133.It Bq Er ENOENT
134The named file does not exist.
135.\" ===========
136.It Bq Er ENOTDIR
137A component of the path prefix is not a directory.
138.El
139.Pp
140In addition to the errors returned by the
141.Fn readlink ,
142the
143.Fn readlinkat
144may fail if:
145.Bl -tag -width Er
146.It Bq Er EBADF
147The
148.Fa path
149argument does not specify an absolute path and the
150.Fa fd
151argument is neither
152.Dv AT_FDCWD
153nor a valid file descriptor open for searching.
154.It Bq Er ENOTDIR
155The
156.Fa path
157argument is not an absolute path and
158.Fa fd
159is neither
160.Dv AT_FDCWD
161nor a file descriptor associated with a directory.
162.El
163.Sh LEGACY SYNOPSIS
164.Fd #include <unistd.h>
165.Pp
166.Ft int
167.br
168.Fo readlink
169.Fa "const char *path"
170.Fa "char *buf"
171.Fa "int bufsize"
172.Fc ;
173.Pp
174The function type and the type of
175.Fa bufsize
176have changed.
177.Sh SEE ALSO
178.Xr lstat 2 ,
179.Xr stat 2 ,
180.Xr symlink 2 ,
181.Xr compat 5 ,
182.Xr symlink 7
183.Sh STANDARDS
184The
185.Fn readlinkat
186system call is expected to conform to POSIX.1-2008 .
187.Sh HISTORY
188The
189.Fn readlink
190function call appeared in
191.Bx 4.2 .
192The
193.Fn readlinkat
194system call appeared in OS X 10.10.
195The
196.Fn freadlink
197system call appeared in macOS 13.0.
198