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 2007-07-26 "" "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)):
43 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
46 expands all symbolic links and resolves references
51 characters in the null terminated string named by
53 and stores the canonicalized absolute pathname in the buffer of size
57 The resulting path will have no symbolic link,
65 returns a pointer to the
68 Otherwise it returns a NULL pointer, and the contents
74 is set to indicate the error.
78 Read or search permission was denied for a component of the path prefix.
85 is NULL. (In libc5 this would just cause a segfault.)
89 An I/O error occurred while reading from the file system.
92 Too many symbolic links were encountered in translating the pathname.
95 A component of a pathname exceeded
97 characters, or an entire pathname exceeded
102 The named file does not exist.
105 A component of the path prefix is not a directory.
107 On Linux this function appeared in libc 4.5.21.
109 4.4BSD, POSIX.1-2001.
111 In 4.4BSD and Solaris the limit on the pathname length is
113 (found in \fI<sys/param.h>\fP).
118 as found in \fI<limits.h>\fP or provided by the
121 A typical source fragment would be
128 path_max = pathconf(path, _PC_PATH_MAX);
134 (But see the BUGS section.)
136 The 4.4BSD, Linux and SUSv2 versions always return an absolute
138 Solaris may return a relative pathname when the
140 argument is relative.
143 is given in \fI<unistd.h>\fP in libc4 and libc5,
144 but in \fI<stdlib.h>\fP everywhere else.
146 The glibc implementation of
148 provides a non-standard extension.
151 is specified as NULL, then
155 to allocate a buffer of up to
157 bytes to hold the resolved pathname,
158 and returns a pointer to this buffer.
159 The caller should deallocate this buffer using
161 .\" Even if we use resolved_path == NULL, then realpath() will still
162 .\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
163 .\" bytes -- MTK, Dec 04
167 .\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
169 Avoid using this function.
170 It is broken by design since (unless
171 using the non-standard
172 .I "resolved_path\ ==\ NULL"
174 impossible to determine a suitable size for the output buffer,
176 According to POSIX a buffer of size
180 need not be a defined constant, and may have to be obtained using
184 does not really help, since on the one hand POSIX warns that
187 may be huge and unsuitable for mallocing memory.
191 may return \-1 to signify that
195 The libc4 and libc5 implementation contains a buffer overflow
196 (fixed in libc-5.4.13).
197 Thus, set-user-ID programs like mount need a private version.
200 .BR canonicalize_file_name (3),