]>
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 | 55 | .Sh DESCRIPTION |
39037602 | 56 | .Fn readlink |
9bccf70c A |
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 | |
5ba3f43e | 88 | .Fn readlink . |
9bccf70c A |
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 | |
39037602 | 95 | .Fn readlink |
9bccf70c A |
96 | will fail if: |
97 | .Bl -tag -width Er | |
2d21ac55 A |
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 | .\" =========== | |
9bccf70c A |
116 | .It Bq Er ENAMETOOLONG |
117 | A component of a pathname exceeded | |
118 | .Dv {NAME_MAX} | |
2d21ac55 A |
119 | characters, or an entire path name |
120 | (possibly expanded by a symbolic link) exceeded | |
9bccf70c A |
121 | .Dv {PATH_MAX} |
122 | characters. | |
2d21ac55 | 123 | .\" =========== |
9bccf70c A |
124 | .It Bq Er ENOENT |
125 | The named file does not exist. | |
2d21ac55 A |
126 | .\" =========== |
127 | .It Bq Er ENOTDIR | |
128 | A component of the path prefix is not a directory. | |
9bccf70c | 129 | .El |
fe8ab488 A |
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 | |
2d21ac55 A |
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. | |
9bccf70c | 168 | .Sh SEE ALSO |
9bccf70c | 169 | .Xr lstat 2 , |
2d21ac55 A |
170 | .Xr stat 2 , |
171 | .Xr symlink 2 , | |
172 | .Xr compat 5 , | |
173 | .Xr symlink 7 | |
fe8ab488 A |
174 | .Sh STANDARDS |
175 | The | |
176 | .Fn readlinkat | |
177 | system call is expected to conform to POSIX.1-2008 . | |
9bccf70c A |
178 | .Sh HISTORY |
179 | The | |
180 | .Fn readlink | |
181 | function call appeared in | |
182 | .Bx 4.2 . | |
fe8ab488 A |
183 | The |
184 | .Fn readlinkat | |
185 | system call appeared in OS X 10.10 |