]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man2/readlink.2
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / man / man2 / readlink.2
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 .Nd read value of a symbolic link
43 .Sh SYNOPSIS
44 .Fd #include <unistd.h>
45 .Ft ssize_t
46 .Fo readlink
47 .Fa "const char *restrict path"
48 .Fa "char *restrict buf"
49 .Fa "size_t bufsize"
50 .Fc
51 .Ft ssize_t
52 .Fo readlinkat
53 .Fa "int fd" "const char *restrict path" "char *restrict buf" "size_t bufsize"
54 .Fc
55 .Sh DESCRIPTION
56 .Fn readlink
57 places the contents of the symbolic link
58 .Fa path
59 in the buffer
60 .Fa buf ,
61 which has size
62 .Fa bufsize .
63 .Nm Readlink
64 does not append a
65 .Dv NUL
66 character to
67 .Fa buf .
68 .Pp
69 The
70 .Fn readlinkat
71 system call is equivalent to
72 .Fn readlink
73 except in the case where
74 .Fa path
75 specifies a relative path.
76 In this case the symbolic link whose content is read relative to the
77 directory associated with the file descriptor
78 .Fa fd
79 instead of the current working directory.
80 If
81 .Fn readlinkat
82 is passed the special value
83 .Dv AT_FDCWD
84 in the
85 .Fa fd
86 parameter, the current working directory is used and the behavior is
87 identical to a call to
88 .Fn readlink .
89 .Sh RETURN VALUES
90 The call returns the count of characters placed in the buffer
91 if it succeeds, or a -1 if an error occurs, placing the error
92 code in the global variable
93 .Va errno .
94 .Sh ERRORS
95 .Fn readlink
96 will fail if:
97 .Bl -tag -width Er
98 .\" ===========
99 .It Bq Er EACCES
100 Search permission is denied for a component of the path prefix.
101 .\" ===========
102 .It Bq Er EFAULT
103 .Fa Buf
104 extends outside the process's allocated address space.
105 .\" ===========
106 .It Bq Er EINVAL
107 The named file is not a symbolic link.
108 .\" ===========
109 .It Bq Er EIO
110 An I/O error occurred while reading from the file system.
111 .\" ===========
112 .It Bq Er ELOOP
113 Too many symbolic links are encountered in translating the pathname.
114 This is taken to be indicative of a looping symbolic link.
115 .\" ===========
116 .It Bq Er ENAMETOOLONG
117 A component of a pathname exceeded
118 .Dv {NAME_MAX}
119 characters, or an entire path name
120 (possibly expanded by a symbolic link) exceeded
121 .Dv {PATH_MAX}
122 characters.
123 .\" ===========
124 .It Bq Er ENOENT
125 The named file does not exist.
126 .\" ===========
127 .It Bq Er ENOTDIR
128 A component of the path prefix is not a directory.
129 .El
130 .Pp
131 In addition to the errors returned by the
132 .Fn readlink ,
133 the
134 .Fn readlinkat
135 may fail if:
136 .Bl -tag -width Er
137 .It Bq Er EBADF
138 The
139 .Fa path
140 argument does not specify an absolute path and the
141 .Fa fd
142 argument is neither
143 .Dv AT_FDCWD
144 nor a valid file descriptor open for searching.
145 .It Bq Er ENOTDIR
146 The
147 .Fa path
148 argument is not an absolute path and
149 .Fa fd
150 is neither
151 .Dv AT_FDCWD
152 nor a file descriptor associated with a directory.
153 .El
154 .Sh LEGACY SYNOPSIS
155 .Fd #include <unistd.h>
156 .Pp
157 .Ft int
158 .br
159 .Fo readlink
160 .Fa "const char *path"
161 .Fa "char *buf"
162 .Fa "int bufsize"
163 .Fc ;
164 .Pp
165 The function type and the type of
166 .Fa bufsize
167 have changed.
168 .Sh SEE ALSO
169 .Xr lstat 2 ,
170 .Xr stat 2 ,
171 .Xr symlink 2 ,
172 .Xr compat 5 ,
173 .Xr symlink 7
174 .Sh STANDARDS
175 The
176 .Fn readlinkat
177 system call is expected to conform to POSIX.1-2008 .
178 .Sh HISTORY
179 The
180 .Fn readlink
181 function call appeared in
182 .Bx 4.2 .
183 The
184 .Fn readlinkat
185 system call appeared in OS X 10.10