]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl) |
2 | .\" | |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
c13182ef | 11 | .\" |
fea681da MK |
12 | .\" Since the Linux kernel and libraries are constantly changing, this |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .\" Rewritten old page, 990824, aeb@cwi.nl | |
7841ad47 | 24 | .\" 2004-12-14, mtk, added discussion of resolved_path == NULL |
fea681da | 25 | .\" |
7841ad47 | 26 | .TH REALPATH 3 2004-12-14 "" "Linux Programmer's Manual" |
fea681da MK |
27 | .SH NAME |
28 | realpath \- return the canonicalized absolute pathname | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <limits.h> | |
32 | .B #include <stdlib.h> | |
33 | .sp | |
c13182ef | 34 | .BI "char *realpath(const char *" path ", char *" resolved_path ); |
fea681da | 35 | .SH DESCRIPTION |
7841ad47 | 36 | .BR realpath () |
fea681da MK |
37 | expands all symbolic links and resolves references |
38 | to | |
c13182ef MK |
39 | .IR '/./' ", " '/../' |
40 | and extra | |
41 | .I '/' | |
42 | characters in the null terminated string named by | |
fea681da MK |
43 | .I path |
44 | and stores the canonicalized absolute pathname in the buffer of size | |
45 | .B PATH_MAX | |
46 | named by | |
47 | .IR resolved_path . | |
48 | The resulting path will have no symbolic link, | |
49 | .I '/./' | |
50 | or | |
51 | .I '/../' | |
52 | components. | |
53 | .SH "RETURN VALUE" | |
7841ad47 MK |
54 | If there is no error, |
55 | .BR realpath () | |
56 | returns a pointer to the | |
fea681da MK |
57 | .IR resolved_path . |
58 | ||
59 | Otherwise it returns a NULL pointer, and the contents | |
60 | of the array | |
c13182ef MK |
61 | .I resolved_path |
62 | are undefined. | |
63 | The global variable | |
64 | .I errno | |
65 | is set to indicate the error. | |
fea681da MK |
66 | .SH ERRORS |
67 | .TP | |
68 | .B EACCES | |
69 | Read or search permission was denied for a component of the path prefix. | |
70 | .TP | |
71 | .B EINVAL | |
72 | Either | |
73 | .I path | |
74 | or | |
75 | .I resolved_path | |
76 | is NULL. (In libc5 this would just cause a segfault.) | |
7841ad47 | 77 | But, see NOTES below. |
fea681da MK |
78 | .TP |
79 | .B EIO | |
80 | An I/O error occurred while reading from the file system. | |
81 | .TP | |
82 | .B ELOOP | |
83 | Too many symbolic links were encountered in translating the pathname. | |
84 | .TP | |
85 | .B ENAMETOOLONG | |
c13182ef | 86 | A component of a pathname exceeded |
fea681da | 87 | .B NAME_MAX |
c13182ef | 88 | characters, or an entire pathname exceeded |
fea681da MK |
89 | .B PATH_MAX |
90 | characters. | |
91 | .TP | |
92 | .B ENOENT | |
93 | The named file does not exist. | |
94 | .TP | |
95 | .B ENOTDIR | |
96 | A component of the path prefix is not a directory. | |
2b2581ee MK |
97 | .SH VERSIONS |
98 | On Linux this function appeared in libc 4.5.21. | |
99 | .SH "CONFORMING TO" | |
100 | 4.4BSD, POSIX.1-2001. | |
101 | ||
102 | In 4.4BSD and Solaris the limit on the pathname length is MAXPATHLEN | |
c84371c6 | 103 | (found in \fI<sys/param.h>\fP). |
2b2581ee | 104 | SUSv2 prescribes PATH_MAX and |
c84371c6 | 105 | NAME_MAX, as found in \fI<limits.h>\fP or provided by the |
2b2581ee MK |
106 | .BR pathconf (3) |
107 | function. | |
108 | A typical source fragment would be | |
109 | .LP | |
110 | .RS | |
111 | .nf | |
112 | #ifdef PATH_MAX | |
113 | path_max = PATH_MAX; | |
114 | #else | |
115 | path_max = pathconf(path, _PC_PATH_MAX); | |
116 | if (path_max <= 0) | |
117 | path_max = 4096; | |
118 | #endif | |
119 | .fi | |
120 | .RE | |
121 | (But see the BUGS section.) | |
122 | .LP | |
123 | The 4.4BSD, Linux and SUSv2 versions always return an absolute | |
124 | pathname. | |
125 | Solaris may return a relative pathname when the | |
126 | .I path | |
127 | argument is relative. | |
128 | The prototype of | |
129 | .BR realpath () | |
c84371c6 MK |
130 | is given in \fI<unistd.h>\fP in libc4 and libc5, |
131 | but in \fI<stdlib.h>\fP everywhere else. | |
7841ad47 MK |
132 | .SH NOTES |
133 | The glibc implementation of | |
134 | .BR realpath () | |
135 | provides a non-standard extension. | |
136 | If | |
137 | .I resolved_path | |
138 | is specified as NULL, then | |
139 | .BR realpath () | |
140 | uses | |
141 | .BR malloc (3) | |
3678235c MK |
142 | to allocate a buffer of up to PATH_MAX bytes |
143 | to hold the resolved pathname, | |
7841ad47 MK |
144 | and returns a pointer to this buffer. |
145 | The caller should deallocate this buffer using | |
146 | .BR free (3). | |
c13182ef MK |
147 | .\" Even if we use resolved_path == NULL, then realpath() will still |
148 | .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX | |
3678235c | 149 | .\" bytes -- MTK, Dec 04 |
2b2581ee MK |
150 | .\" .SH HISTORY |
151 | .\" The | |
152 | .\" .BR realpath () | |
153 | .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry. | |
fea681da | 154 | .SH BUGS |
c13182ef MK |
155 | Avoid using this function. |
156 | It is broken by design since (unless | |
3678235c MK |
157 | using the non-standard |
158 | .I "resolved_path\ ==\ NULL" | |
159 | feature) it is | |
7841ad47 MK |
160 | impossible to determine a suitable size for the output buffer, |
161 | .IR resolved_path . | |
fea681da MK |
162 | According to POSIX a buffer of size PATH_MAX suffices, but |
163 | PATH_MAX need not be a defined constant, and may have to be | |
164 | obtained using | |
fb186734 | 165 | .BR pathconf (3). |
fea681da | 166 | And asking |
fb186734 | 167 | .BR pathconf (3) |
fea681da MK |
168 | does not really help, since on the one hand POSIX warns that |
169 | the result of | |
fb186734 | 170 | .BR pathconf (3) |
c13182ef MK |
171 | may be huge and unsuitable for mallocing memory. |
172 | And on the other | |
fea681da | 173 | hand |
fb186734 | 174 | .BR pathconf (3) |
fea681da MK |
175 | may return \-1 to signify that PATH_MAX is not bounded. |
176 | .LP | |
177 | The libc4 and libc5 implementation contains a buffer overflow | |
178 | (fixed in libc-5.4.13). | |
a8431b7b | 179 | Thus, set-user-ID programs like mount need a private version. |
fea681da MK |
180 | .SH "SEE ALSO" |
181 | .BR readlink (2), | |
a8431b7b | 182 | .BR canonicalize_file_name (3), |
fea681da MK |
183 | .BR getcwd (3), |
184 | .BR pathconf (3), | |
185 | .BR sysconf (3) |