1 .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Rewritten old page, 990824, aeb@cwi.nl
26 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
28 .TH REALPATH 3 2017-09-15 "" "Linux Programmer's Manual"
30 realpath \- return the canonicalized absolute pathname
33 .B #include <limits.h>
34 .B #include <stdlib.h>
36 .BI "char *realpath(const char *" path ", char *" resolved_path );
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
47 _XOPEN_SOURCE\ >=\ 500
48 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
49 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
50 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
55 expands all symbolic links and resolves references
59 characters in the null-terminated string named by
61 to produce a canonicalized absolute pathname.
62 The resulting pathname is stored as a null-terminated string,
66 in the buffer pointed to by
68 The resulting path will have no symbolic link,
76 is specified as NULL, then
80 to allocate a buffer of up to
82 bytes to hold the resolved pathname,
83 and returns a pointer to this buffer.
84 The caller should deallocate this buffer using
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
92 .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
96 returns a pointer to the
99 Otherwise, it returns NULL, the contents
104 is set to indicate the error.
108 Read or search permission was denied for a component of the path prefix.
113 .\" (In libc5 this would just cause a segfault.)
114 (In glibc versions before 2.3,
115 this error is also returned if
120 An I/O error occurred while reading from the filesystem.
123 Too many symbolic links were encountered in translating the pathname.
126 A component of a pathname exceeded
128 characters, or an entire pathname exceeded
133 The named file does not exist.
139 A component of the path prefix is not a directory.
141 For an explanation of the terms used in this section, see
147 Interface Attribute Value
150 T} Thread safety MT-Safe
153 4.4BSD, POSIX.1-2001.
155 POSIX.1-2001 says that the behavior if
157 is NULL is implementation-defined.
158 POSIX.1-2008 specifies the behavior described in this page.
160 In 4.4BSD and Solaris, the limit on the pathname length is
162 (found in \fI<sys/param.h>\fP).
167 as found in \fI<limits.h>\fP or provided by the
170 A typical source fragment would be
177 path_max = pathconf(path, _PC_PATH_MAX);
184 (But see the BUGS section.)
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.
190 .\" The 4.4BSD, Linux and SUSv2 versions always return an absolute
192 .\" Solaris may return a relative pathname when the
194 .\" argument is relative.
197 .\" is given in \fI<unistd.h>\fP in libc4 and libc5,
198 .\" but in \fI<stdlib.h>\fP everywhere else.
200 If the call fails with either
206 is not NULL, then the prefix of
208 that is not readable or does not exist is returned in
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,
214 According to POSIX.1-2001 a buffer of size
218 need not be a defined constant, and may have to be obtained using
222 does not really help, since, on the one hand POSIX warns that
225 may be huge and unsuitable for mallocing memory,
226 and on the other hand
228 may return \-1 to signify that
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.
236 .\" The libc4 and libc5 implementation contained a buffer overflow
237 .\" (fixed in libc-5.4.13).
238 .\" Thus, set-user-ID programs like
240 .\" needed a private version.
244 .BR canonicalize_file_name (3),