2 .\" Copyright (C) 1999 Andries Brouwer (aeb@cwi.nl)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" Rewritten old page, 990824, aeb@cwi.nl
7 .\" 2004-12-14, mtk, added discussion of resolved_path == NULL
9 .TH realpath 3 (date) "Linux man-pages (unreleased)"
11 realpath \- return the canonicalized absolute pathname
14 .RI ( libc ", " \-lc )
17 .B #include <limits.h>
18 .B #include <stdlib.h>
20 .BI "char *realpath(const char *restrict " path ,
21 .BI " char *restrict " resolved_path );
25 Feature Test Macro Requirements for glibc (see
26 .BR feature_test_macros (7)):
32 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
33 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
34 || /* glibc <= 2.19: */ _BSD_SOURCE
38 expands all symbolic links and resolves references
42 characters in the null-terminated string named by
44 to produce a canonicalized absolute pathname.
45 The resulting pathname is stored as a null-terminated string,
49 in the buffer pointed to by
51 The resulting path will have no symbolic link,
59 is specified as NULL, then
63 to allocate a buffer of up to
65 bytes to hold the resolved pathname,
66 and returns a pointer to this buffer.
67 The caller should deallocate this buffer using
69 .\" Even if we use resolved_path == NULL, then realpath() will still
70 .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
71 .\" bytes -- MTK, Dec 04
75 returns a pointer to the
78 Otherwise, it returns NULL, the contents
83 is set to indicate the error.
87 Read or search permission was denied for a component of the path prefix.
92 .\" (In libc5 this would just cause a segfault.)
94 this error is also returned if
99 An I/O error occurred while reading from the filesystem.
102 Too many symbolic links were encountered in translating the pathname.
105 A component of a pathname exceeded
107 characters, or an entire pathname exceeded
112 The named file does not exist.
118 A component of the path prefix is not a directory.
120 For an explanation of the terms used in this section, see
128 Interface Attribute Value
131 T} Thread safety MT-Safe
138 If the call fails with either
144 is not NULL, then the prefix of
146 that is not readable or does not exist is returned in
151 4.4BSD, POSIX.1-2001, Solaris.
153 POSIX.1-2001 says that the behavior if
155 is NULL is implementation-defined.
156 POSIX.1-2008 specifies the behavior described in this page.
158 In 4.4BSD and Solaris, the limit on the pathname length is
160 (found in \fI<sys/param.h>\fP).
165 as found in \fI<limits.h>\fP or provided by the
168 A typical source fragment would be
175 path_max = pathconf(path, _PC_PATH_MAX);
182 (But see the BUGS section.)
184 .\" 2012-05-05, According to Casper Dik, the statement about
185 .\" Solaris was not true at least as far back as 1997, and
186 .\" may never have been true.
188 .\" The 4.4BSD, Linux and SUSv2 versions always return an absolute
190 .\" Solaris may return a relative pathname when the
192 .\" argument is relative.
195 .\" is given in \fI<unistd.h>\fP in libc4 and libc5,
196 .\" but in \fI<stdlib.h>\fP everywhere else.
198 The POSIX.1-2001 standard version of this function is broken by design,
199 since it is impossible to determine a suitable size for the output buffer,
201 According to POSIX.1-2001 a buffer of size
205 need not be a defined constant, and may have to be obtained using
209 does not really help, since, on the one hand POSIX warns that
212 may be huge and unsuitable for mallocing memory,
213 and on the other hand
215 may return \-1 to signify that
219 .I "resolved_path\ ==\ NULL"
220 feature, not standardized in POSIX.1-2001,
221 but standardized in POSIX.1-2008, allows this design problem to be avoided.
223 .\" The libc4 and libc5 implementation contained a buffer overflow
224 .\" (fixed in libc-5.4.13).
225 .\" Thus, set-user-ID programs like
227 .\" needed a private version.
231 .BR canonicalize_file_name (3),