]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/realpath.3
ctime.3: clarify mktime()'s use of tm_isdst
[thirdparty/man-pages.git] / man3 / realpath.3
CommitLineData
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.\"
55e80e25 26.TH REALPATH 3 2008-08-21 "" "Linux Programmer's Manual"
fea681da
MK
27.SH NAME
28realpath \- 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 );
cc4615cc
MK
35.fi
36.sp
37.in -4n
38Feature Test Macro Requirements for glibc (see
39.BR feature_test_macros (7)):
40.in
41.sp
42.BR realpath ():
43_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
fea681da 44.SH DESCRIPTION
7841ad47 45.BR realpath ()
fea681da
MK
46expands all symbolic links and resolves references
47to
f8a07a21 48.IR "/./" ", " "/../"
f81fb444 49and extra \(aq/\(aq
c13182ef 50characters in the null terminated string named by
fea681da
MK
51.I path
52and stores the canonicalized absolute pathname in the buffer of size
53.B PATH_MAX
54named by
55.IR resolved_path .
56The resulting path will have no symbolic link,
f8a07a21 57.I "/./"
fea681da 58or
f8a07a21 59.I "/../"
fea681da 60components.
55e80e25
MK
61
62If
63.I resolved_path
64is specified as NULL, then
65.BR realpath ()
66uses
67.BR malloc (3)
68to allocate a buffer of up to
69.B PATH_MAX
70bytes to hold the resolved pathname,
71and returns a pointer to this buffer.
72The caller should deallocate this buffer using
73.BR free (3).
74.\" Even if we use resolved_path == NULL, then realpath() will still
75.\" return ENAMETOOLONG if the resolved pathname would exceed PATH_MAX
76.\" bytes -- MTK, Dec 04
77.\" .SH HISTORY
78.\" The
79.\" .BR realpath ()
80.\" function first appeared in 4.4BSD, contributed by Jan-Simon Pendry.
fea681da 81.SH "RETURN VALUE"
7841ad47
MK
82If there is no error,
83.BR realpath ()
84returns a pointer to the
fea681da
MK
85.IR resolved_path .
86
87Otherwise it returns a NULL pointer, and the contents
88of the array
c13182ef
MK
89.I resolved_path
90are undefined.
91The global variable
92.I errno
93is set to indicate the error.
fea681da
MK
94.SH ERRORS
95.TP
96.B EACCES
97Read or search permission was denied for a component of the path prefix.
98.TP
99.B EINVAL
100Either
101.I path
102or
103.I resolved_path
6387216b
MK
104is NULL.
105(In libc5 this would just cause a segfault.)
7841ad47 106But, see NOTES below.
fea681da
MK
107.TP
108.B EIO
109An I/O error occurred while reading from the file system.
110.TP
111.B ELOOP
112Too many symbolic links were encountered in translating the pathname.
113.TP
114.B ENAMETOOLONG
c13182ef 115A component of a pathname exceeded
fea681da 116.B NAME_MAX
c13182ef 117characters, or an entire pathname exceeded
fea681da
MK
118.B PATH_MAX
119characters.
120.TP
121.B ENOENT
122The named file does not exist.
123.TP
124.B ENOTDIR
125A component of the path prefix is not a directory.
2b2581ee
MK
126.SH VERSIONS
127On Linux this function appeared in libc 4.5.21.
128.SH "CONFORMING TO"
1294.4BSD, POSIX.1-2001.
130
55e80e25
MK
131POSIX.1 says that the behavior if
132.I resolved_path
133is NULL is implementation-defined.
134POSIX.1-2008 specifies the behavior described in this page.
2f0af33b
MK
135In 4.4BSD and Solaris the limit on the pathname length is
136.B MAXPATHLEN
c84371c6 137(found in \fI<sys/param.h>\fP).
2f0af33b 138SUSv2 prescribes
0daa9e92 139.B PATH_MAX
2f0af33b
MK
140and
141.BR NAME_MAX ,
142as found in \fI<limits.h>\fP or provided by the
2b2581ee
MK
143.BR pathconf (3)
144function.
145A typical source fragment would be
146.LP
a6e2f128 147.in +4n
2b2581ee
MK
148.nf
149#ifdef PATH_MAX
150 path_max = PATH_MAX;
151#else
152 path_max = pathconf(path, _PC_PATH_MAX);
153 if (path_max <= 0)
154 path_max = 4096;
155#endif
156.fi
a6e2f128 157.in
d2d293ba 158.LP
2b2581ee
MK
159(But see the BUGS section.)
160.LP
161The 4.4BSD, Linux and SUSv2 versions always return an absolute
162pathname.
163Solaris may return a relative pathname when the
164.I path
165argument is relative.
166The prototype of
167.BR realpath ()
c84371c6
MK
168is given in \fI<unistd.h>\fP in libc4 and libc5,
169but in \fI<stdlib.h>\fP everywhere else.
fea681da 170.SH BUGS
c13182ef
MK
171Avoid using this function.
172It is broken by design since (unless
3678235c
MK
173using the non-standard
174.I "resolved_path\ ==\ NULL"
175feature) it is
7841ad47
MK
176impossible to determine a suitable size for the output buffer,
177.IR resolved_path .
2f0af33b
MK
178According to POSIX a buffer of size
179.B PATH_MAX
180suffices, but
181.B PATH_MAX
182need not be a defined constant, and may have to be obtained using
fb186734 183.BR pathconf (3).
fea681da 184And asking
fb186734 185.BR pathconf (3)
fea681da
MK
186does not really help, since on the one hand POSIX warns that
187the result of
fb186734 188.BR pathconf (3)
c13182ef
MK
189may be huge and unsuitable for mallocing memory.
190And on the other
fea681da 191hand
fb186734 192.BR pathconf (3)
2f0af33b
MK
193may return \-1 to signify that
194.B PATH_MAX
195is not bounded.
fea681da
MK
196.LP
197The libc4 and libc5 implementation contains a buffer overflow
198(fixed in libc-5.4.13).
d9a10d9d
MK
199Thus, set-user-ID programs like
200.BR mount (8)
201need a private version.
fea681da
MK
202.SH "SEE ALSO"
203.BR readlink (2),
a8431b7b 204.BR canonicalize_file_name (3),
fea681da
MK
205.BR getcwd (3),
206.BR pathconf (3),
207.BR sysconf (3)