]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
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 | |
fe8ab488 A |
40 | .Nm readlink , |
41 | .Nm readlinkat | |
9bccf70c A |
42 | .Nd read value of a symbolic link |
43 | .Sh SYNOPSIS | |
44 | .Fd #include <unistd.h> | |
2d21ac55 A |
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 | |
fe8ab488 A |
51 | .Ft ssize_t |
52 | .Fo readlinkat | |
53 | .Fa "int fd" "const char *restrict path" "char *restrict buf" "size_t bufsize" | |
54 | .Fc | |
9bccf70c A |
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 | |
2d21ac55 | 62 | .Fa bufsize . |
9bccf70c A |
63 | .Nm Readlink |
64 | does not append a | |
65 | .Dv NUL | |
66 | character to | |
67 | .Fa buf . | |
fe8ab488 A |
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 | |
9bccf70c A |
88 | .Sh RETURN VALUES |
89 | The call returns the count of characters placed in the buffer | |
90 | if it succeeds, or a -1 if an error occurs, placing the error | |
91 | code in the global variable | |
92 | .Va errno . | |
93 | .Sh ERRORS | |
94 | .Fn Readlink | |
95 | will fail if: | |
96 | .Bl -tag -width Er | |
2d21ac55 A |
97 | .\" =========== |
98 | .It Bq Er EACCES | |
99 | Search permission is denied for a component of the path prefix. | |
100 | .\" =========== | |
101 | .It Bq Er EFAULT | |
102 | .Fa Buf | |
103 | extends outside the process's allocated address space. | |
104 | .\" =========== | |
105 | .It Bq Er EINVAL | |
106 | The named file is not a symbolic link. | |
107 | .\" =========== | |
108 | .It Bq Er EIO | |
109 | An I/O error occurred while reading from the file system. | |
110 | .\" =========== | |
111 | .It Bq Er ELOOP | |
112 | Too many symbolic links are encountered in translating the pathname. | |
113 | This is taken to be indicative of a looping symbolic link. | |
114 | .\" =========== | |
9bccf70c A |
115 | .It Bq Er ENAMETOOLONG |
116 | A component of a pathname exceeded | |
117 | .Dv {NAME_MAX} | |
2d21ac55 A |
118 | characters, or an entire path name |
119 | (possibly expanded by a symbolic link) exceeded | |
9bccf70c A |
120 | .Dv {PATH_MAX} |
121 | characters. | |
2d21ac55 | 122 | .\" =========== |
9bccf70c A |
123 | .It Bq Er ENOENT |
124 | The named file does not exist. | |
2d21ac55 A |
125 | .\" =========== |
126 | .It Bq Er ENOTDIR | |
127 | A component of the path prefix is not a directory. | |
9bccf70c | 128 | .El |
fe8ab488 A |
129 | .Pp |
130 | In addition to the errors returned by the | |
131 | .Fn readlink , | |
132 | the | |
133 | .Fn readlinkat | |
134 | may fail if: | |
135 | .Bl -tag -width Er | |
136 | .It Bq Er EBADF | |
137 | The | |
138 | .Fa path | |
139 | argument does not specify an absolute path and the | |
140 | .Fa fd | |
141 | argument is neither | |
142 | .Dv AT_FDCWD | |
143 | nor a valid file descriptor open for searching. | |
144 | .It Bq Er ENOTDIR | |
145 | The | |
146 | .Fa path | |
147 | argument is not an absolute path and | |
148 | .Fa fd | |
149 | is neither | |
150 | .Dv AT_FDCWD | |
151 | nor a file descriptor associated with a directory. | |
152 | .El | |
2d21ac55 A |
153 | .Sh LEGACY SYNOPSIS |
154 | .Fd #include <unistd.h> | |
155 | .Pp | |
156 | .Ft int | |
157 | .br | |
158 | .Fo readlink | |
159 | .Fa "const char *path" | |
160 | .Fa "char *buf" | |
161 | .Fa "int bufsize" | |
162 | .Fc ; | |
163 | .Pp | |
164 | The function type and the type of | |
165 | .Fa bufsize | |
166 | have changed. | |
9bccf70c | 167 | .Sh SEE ALSO |
9bccf70c | 168 | .Xr lstat 2 , |
2d21ac55 A |
169 | .Xr stat 2 , |
170 | .Xr symlink 2 , | |
171 | .Xr compat 5 , | |
172 | .Xr symlink 7 | |
fe8ab488 A |
173 | .Sh STANDARDS |
174 | The | |
175 | .Fn readlinkat | |
176 | system call is expected to conform to POSIX.1-2008 . | |
9bccf70c A |
177 | .Sh HISTORY |
178 | The | |
179 | .Fn readlink | |
180 | function call appeared in | |
181 | .Bx 4.2 . | |
fe8ab488 A |
182 | The |
183 | .Fn readlinkat | |
184 | system call appeared in OS X 10.10 |