]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" Rewritten old page, 990824, aeb@cwi.nl | |
7841ad47 | 26 | .\" 2004-12-14, mtk, added discussion of resolved_path == NULL |
fea681da | 27 | .\" |
4b8c67d9 | 28 | .TH REALPATH 3 2017-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
29 | .SH NAME |
30 | realpath \- return the canonicalized absolute pathname | |
31 | .SH SYNOPSIS | |
32 | .nf | |
33 | .B #include <limits.h> | |
34 | .B #include <stdlib.h> | |
68e4db0a | 35 | .PP |
c13182ef | 36 | .BI "char *realpath(const char *" path ", char *" resolved_path ); |
cc4615cc | 37 | .fi |
68e4db0a | 38 | .PP |
cc4615cc MK |
39 | .in -4n |
40 | Feature Test Macro Requirements for glibc (see | |
41 | .BR feature_test_macros (7)): | |
42 | .in | |
68e4db0a | 43 | .PP |
cc4615cc | 44 | .BR realpath (): |
a440dd9b MK |
45 | .ad l |
46 | .RS 4 | |
2b1b0424 | 47 | _XOPEN_SOURCE\ >=\ 500 |
cf7fa0a1 | 48 | .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED |
2b1b0424 MK |
49 | || /* Glibc since 2.19: */ _DEFAULT_SOURCE |
50 | || /* Glibc versions <= 2.19: */ _BSD_SOURCE | |
a440dd9b MK |
51 | .RE |
52 | .ad | |
fea681da | 53 | .SH DESCRIPTION |
7841ad47 | 54 | .BR realpath () |
fea681da MK |
55 | expands all symbolic links and resolves references |
56 | to | |
f8a07a21 | 57 | .IR "/./" ", " "/../" |
f81fb444 | 58 | and extra \(aq/\(aq |
d0cb7cc6 | 59 | characters in the null-terminated string named by |
fea681da | 60 | .I path |
bf0e2b8a MK |
61 | to produce a canonicalized absolute pathname. |
62 | The resulting pathname is stored as a null-terminated string, | |
63 | up to a maximum of | |
fea681da | 64 | .B PATH_MAX |
5a3b4036 | 65 | bytes, |
bf0e2b8a | 66 | in the buffer pointed to by |
fea681da MK |
67 | .IR resolved_path . |
68 | The resulting path will have no symbolic link, | |
f8a07a21 | 69 | .I "/./" |
fea681da | 70 | or |
f8a07a21 | 71 | .I "/../" |
fea681da | 72 | components. |
847e0d88 | 73 | .PP |
55e80e25 MK |
74 | If |
75 | .I resolved_path | |
76 | is specified as NULL, then | |
77 | .BR realpath () | |
78 | uses | |
79 | .BR malloc (3) | |
80 | to allocate a buffer of up to | |
81 | .B PATH_MAX | |
82 | bytes to hold the resolved pathname, | |
83 | and returns a pointer to this buffer. | |
84 | The caller should deallocate this buffer using | |
85 | .BR free (3). | |
86 | .\" Even if we use resolved_path == NULL, then realpath() will still | |
87 | .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX | |
88 | .\" bytes -- MTK, Dec 04 | |
89 | .\" .SH HISTORY | |
90 | .\" The | |
91 | .\" .BR realpath () | |
92 | .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry. | |
47297adb | 93 | .SH RETURN VALUE |
7841ad47 MK |
94 | If there is no error, |
95 | .BR realpath () | |
96 | returns a pointer to the | |
fea681da | 97 | .IR resolved_path . |
847e0d88 | 98 | .PP |
b437fdd9 | 99 | Otherwise, it returns NULL, the contents |
fea681da | 100 | of the array |
c13182ef | 101 | .I resolved_path |
28d03ce9 | 102 | are undefined, and |
c13182ef MK |
103 | .I errno |
104 | is set to indicate the error. | |
fea681da MK |
105 | .SH ERRORS |
106 | .TP | |
107 | .B EACCES | |
108 | Read or search permission was denied for a component of the path prefix. | |
109 | .TP | |
110 | .B EINVAL | |
fea681da | 111 | .I path |
6387216b | 112 | is NULL. |
536bc966 MK |
113 | .\" (In libc5 this would just cause a segfault.) |
114 | (In glibc versions before 2.3, | |
115 | this error is also returned if | |
116 | .IR resolved_path | |
117 | is NULL.) | |
fea681da MK |
118 | .TP |
119 | .B EIO | |
9ee4a2b6 | 120 | An I/O error occurred while reading from the filesystem. |
fea681da MK |
121 | .TP |
122 | .B ELOOP | |
123 | Too many symbolic links were encountered in translating the pathname. | |
124 | .TP | |
125 | .B ENAMETOOLONG | |
c13182ef | 126 | A component of a pathname exceeded |
fea681da | 127 | .B NAME_MAX |
c13182ef | 128 | characters, or an entire pathname exceeded |
fea681da MK |
129 | .B PATH_MAX |
130 | characters. | |
131 | .TP | |
132 | .B ENOENT | |
133 | The named file does not exist. | |
134 | .TP | |
66ced968 MK |
135 | .B ENOMEM |
136 | Out of memory. | |
137 | .TP | |
fea681da MK |
138 | .B ENOTDIR |
139 | A component of the path prefix is not a directory. | |
3b8c8d78 MS |
140 | .SH ATTRIBUTES |
141 | For an explanation of the terms used in this section, see | |
142 | .BR attributes (7). | |
143 | .TS | |
144 | allbox; | |
145 | lb lb lb | |
146 | l l l. | |
147 | Interface Attribute Value | |
148 | T{ | |
149 | .BR realpath () | |
150 | T} Thread safety MT-Safe | |
151 | .TE | |
47297adb | 152 | .SH CONFORMING TO |
2b2581ee | 153 | 4.4BSD, POSIX.1-2001. |
847e0d88 | 154 | .PP |
c49e8fc9 | 155 | POSIX.1-2001 says that the behavior if |
55e80e25 MK |
156 | .I resolved_path |
157 | is NULL is implementation-defined. | |
158 | POSIX.1-2008 specifies the behavior described in this page. | |
c49e8fc9 | 159 | .SH NOTES |
2221c1b9 | 160 | In 4.4BSD and Solaris, the limit on the pathname length is |
2f0af33b | 161 | .B MAXPATHLEN |
c84371c6 | 162 | (found in \fI<sys/param.h>\fP). |
2f0af33b | 163 | SUSv2 prescribes |
0daa9e92 | 164 | .B PATH_MAX |
2f0af33b MK |
165 | and |
166 | .BR NAME_MAX , | |
167 | as found in \fI<limits.h>\fP or provided by the | |
2b2581ee MK |
168 | .BR pathconf (3) |
169 | function. | |
170 | A typical source fragment would be | |
dd3568a1 | 171 | .PP |
a6e2f128 | 172 | .in +4n |
b8302363 | 173 | .EX |
2b2581ee MK |
174 | #ifdef PATH_MAX |
175 | path_max = PATH_MAX; | |
176 | #else | |
177 | path_max = pathconf(path, _PC_PATH_MAX); | |
178 | if (path_max <= 0) | |
179 | path_max = 4096; | |
180 | #endif | |
b8302363 | 181 | .EE |
a6e2f128 | 182 | .in |
dd3568a1 | 183 | .PP |
2b2581ee | 184 | (But see the BUGS section.) |
dd3568a1 | 185 | .PP |
8f826cd8 MK |
186 | .\" 2012-05-05, According to Casper Dik, the statement about |
187 | .\" Solaris was not true at least as far back as 1997, and | |
188 | .\" may never have been true. | |
189 | .\" | |
190 | .\" The 4.4BSD, Linux and SUSv2 versions always return an absolute | |
191 | .\" pathname. | |
192 | .\" Solaris may return a relative pathname when the | |
193 | .\" .I path | |
194 | .\" argument is relative. | |
788b19a2 MK |
195 | .\" The prototype of |
196 | .\" .BR realpath () | |
197 | .\" is given in \fI<unistd.h>\fP in libc4 and libc5, | |
198 | .\" but in \fI<stdlib.h>\fP everywhere else. | |
0bba64e4 MK |
199 | .SS GNU extensions |
200 | If the call fails with either | |
201 | .BR EACCES | |
202 | or | |
203 | .BR ENOENT | |
204 | and | |
205 | .I resolved_path | |
206 | is not NULL, then the prefix of | |
207 | .I path | |
208 | that is not readable or does not exist is returned in | |
209 | .IR resolved_path . | |
fea681da | 210 | .SH BUGS |
c49e8fc9 MK |
211 | The POSIX.1-2001 standard version of this function is broken by design, |
212 | since it is impossible to determine a suitable size for the output buffer, | |
7841ad47 | 213 | .IR resolved_path . |
c49e8fc9 | 214 | According to POSIX.1-2001 a buffer of size |
2f0af33b MK |
215 | .B PATH_MAX |
216 | suffices, but | |
217 | .B PATH_MAX | |
218 | need not be a defined constant, and may have to be obtained using | |
fb186734 | 219 | .BR pathconf (3). |
fea681da | 220 | And asking |
fb186734 | 221 | .BR pathconf (3) |
c49e8fc9 | 222 | does not really help, since, on the one hand POSIX warns that |
fea681da | 223 | the result of |
fb186734 | 224 | .BR pathconf (3) |
c49e8fc9 MK |
225 | may be huge and unsuitable for mallocing memory, |
226 | and on the other hand | |
fb186734 | 227 | .BR pathconf (3) |
2f0af33b MK |
228 | may return \-1 to signify that |
229 | .B PATH_MAX | |
230 | is not bounded. | |
c49e8fc9 MK |
231 | The |
232 | .I "resolved_path\ ==\ NULL" | |
233 | feature, not standardized in POSIX.1-2001, | |
234 | but standardized in POSIX.1-2008, allows this design problem to be avoided. | |
788b19a2 MK |
235 | .\" .LP |
236 | .\" The libc4 and libc5 implementation contained a buffer overflow | |
237 | .\" (fixed in libc-5.4.13). | |
238 | .\" Thus, set-user-ID programs like | |
239 | .\" .BR mount (8) | |
240 | .\" needed a private version. | |
47297adb | 241 | .SH SEE ALSO |
9e4f79d4 | 242 | .BR realpath (1), |
fea681da | 243 | .BR readlink (2), |
a8431b7b | 244 | .BR canonicalize_file_name (3), |
fea681da MK |
245 | .BR getcwd (3), |
246 | .BR pathconf (3), | |
247 | .BR sysconf (3) |