1 .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Rewritten old page, 990824, aeb@cwi.nl
24 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
26 .TH REALPATH 3 2011-09-10 "" "Linux Programmer's Manual"
28 realpath \- return the canonicalized absolute pathname
31 .B #include <limits.h>
32 .B #include <stdlib.h>
34 .BI "char *realpath(const char *" path ", char *" resolved_path );
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
45 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
46 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
51 expands all symbolic links and resolves references
55 characters in the null-terminated string named by
57 to produce a canonicalized absolute pathname.
58 The resulting pathname is stored as a null-terminated string,
62 in the buffer pointed to by
64 The resulting path will have no symbolic link,
72 is specified as NULL, then
76 to allocate a buffer of up to
78 bytes to hold the resolved pathname,
79 and returns a pointer to this buffer.
80 The caller should deallocate this buffer using
82 .\" Even if we use resolved_path == NULL, then realpath() will still
83 .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
84 .\" bytes -- MTK, Dec 04
88 .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
92 returns a pointer to the
95 Otherwise it returns a NULL pointer, and the contents
100 is set to indicate the error.
104 Read or search permission was denied for a component of the path prefix.
109 .\" (In libc5 this would just cause a segfault.)
110 (In glibc versions before 2.3,
111 this error is also returned if
116 An I/O error occurred while reading from the file system.
119 Too many symbolic links were encountered in translating the pathname.
122 A component of a pathname exceeded
124 characters, or an entire pathname exceeded
129 The named file does not exist.
132 A component of the path prefix is not a directory.
134 On Linux this function appeared in libc 4.5.21.
136 4.4BSD, POSIX.1-2001.
138 POSIX.1-2001 says that the behavior if
140 is NULL is implementation-defined.
141 POSIX.1-2008 specifies the behavior described in this page.
143 In 4.4BSD and Solaris the limit on the pathname length is
145 (found in \fI<sys/param.h>\fP).
150 as found in \fI<limits.h>\fP or provided by the
153 A typical source fragment would be
160 path_max = pathconf(path, _PC_PATH_MAX);
167 (But see the BUGS section.)
169 The 4.4BSD, Linux and SUSv2 versions always return an absolute
171 Solaris may return a relative pathname when the
173 argument is relative.
176 is given in \fI<unistd.h>\fP in libc4 and libc5,
177 but in \fI<stdlib.h>\fP everywhere else.
179 The POSIX.1-2001 standard version of this function is broken by design,
180 since it is impossible to determine a suitable size for the output buffer,
182 According to POSIX.1-2001 a buffer of size
186 need not be a defined constant, and may have to be obtained using
190 does not really help, since, on the one hand POSIX warns that
193 may be huge and unsuitable for mallocing memory,
194 and on the other hand
196 may return \-1 to signify that
200 .I "resolved_path\ ==\ NULL"
201 feature, not standardized in POSIX.1-2001,
202 but standardized in POSIX.1-2008, allows this design problem to be avoided.
204 The libc4 and libc5 implementation contains a buffer overflow
205 (fixed in libc-5.4.13).
206 Thus, set-user-ID programs like
208 need a private version.
211 .BR canonicalize_file_name (3),