356 lines
7.3 KiB
HTML
356 lines
7.3 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of REALPATH</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>REALPATH</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
realpath - return the canonicalized absolute pathname
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/limits.h">limits.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></B>
|
|
|
|
<B>char *realpath(const char *</B><I>path</I><B>, char *</B><I>resolved_path</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>realpath</B>():
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_XOPEN_SOURCE >= 500
|
|
|
|
<BR> || /* Glibc since 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>realpath</B>()
|
|
|
|
expands all symbolic links and resolves references
|
|
to
|
|
<I>/./</I>, <I>/../</I>
|
|
|
|
and extra '/'
|
|
characters in the null-terminated string named by
|
|
<I>path</I>
|
|
|
|
to produce a canonicalized absolute pathname.
|
|
The resulting pathname is stored as a null-terminated string,
|
|
up to a maximum of
|
|
<B>PATH_MAX</B>
|
|
|
|
bytes,
|
|
in the buffer pointed to by
|
|
<I>resolved_path</I>.
|
|
|
|
The resulting path will have no symbolic link,
|
|
<I>/./</I>
|
|
|
|
or
|
|
<I>/../</I>
|
|
|
|
components.
|
|
<P>
|
|
|
|
If
|
|
<I>resolved_path</I>
|
|
|
|
is specified as NULL, then
|
|
<B>realpath</B>()
|
|
|
|
uses
|
|
<B><A HREF="/cgi-bin/man/man2html?3+malloc">malloc</A></B>(3)
|
|
|
|
to allocate a buffer of up to
|
|
<B>PATH_MAX</B>
|
|
|
|
bytes to hold the resolved pathname,
|
|
and returns a pointer to this buffer.
|
|
The caller should deallocate this buffer using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+free">free</A></B>(3).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
If there is no error,
|
|
<B>realpath</B>()
|
|
|
|
returns a pointer to the
|
|
<I>resolved_path</I>.
|
|
|
|
<P>
|
|
|
|
Otherwise, it returns NULL, the contents
|
|
of the array
|
|
<I>resolved_path</I>
|
|
|
|
are undefined, and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>EACCES</B>
|
|
|
|
<DD>
|
|
Read or search permission was denied for a component of the path prefix.
|
|
<DT id="3"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>path</I>
|
|
|
|
is NULL.
|
|
|
|
(In glibc versions before 2.3,
|
|
this error is also returned if
|
|
<I>resolved_path</I>
|
|
|
|
is NULL.)
|
|
<DT id="4"><B>EIO</B>
|
|
|
|
<DD>
|
|
An I/O error occurred while reading from the filesystem.
|
|
<DT id="5"><B>ELOOP</B>
|
|
|
|
<DD>
|
|
Too many symbolic links were encountered in translating the pathname.
|
|
<DT id="6"><B>ENAMETOOLONG</B>
|
|
|
|
<DD>
|
|
A component of a pathname exceeded
|
|
<B>NAME_MAX</B>
|
|
|
|
characters, or an entire pathname exceeded
|
|
<B>PATH_MAX</B>
|
|
|
|
characters.
|
|
<DT id="7"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
The named file does not exist.
|
|
<DT id="8"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Out of memory.
|
|
<DT id="9"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
A component of the path prefix is not a directory.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>realpath</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
4.4BSD, POSIX.1-2001.
|
|
<P>
|
|
|
|
POSIX.1-2001 says that the behavior if
|
|
<I>resolved_path</I>
|
|
|
|
is NULL is implementation-defined.
|
|
POSIX.1-2008 specifies the behavior described in this page.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
In 4.4BSD and Solaris, the limit on the pathname length is
|
|
<B>MAXPATHLEN</B>
|
|
|
|
(found in <I><<A HREF="file:///usr/include/sys/param.h">sys/param.h</A>></I>).
|
|
SUSv2 prescribes
|
|
<B>PATH_MAX</B>
|
|
|
|
and
|
|
<B>NAME_MAX</B>,
|
|
|
|
as found in <I><<A HREF="file:///usr/include/limits.h">limits.h</A>></I> or provided by the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3)
|
|
|
|
function.
|
|
A typical source fragment would be
|
|
<P>
|
|
|
|
|
|
|
|
#ifdef PATH_MAX
|
|
<BR> path_max = PATH_MAX;
|
|
#else
|
|
<BR> path_max = pathconf(path, _PC_PATH_MAX);
|
|
<BR> if (path_max <= 0)
|
|
<BR> path_max = 4096;
|
|
#endif
|
|
|
|
|
|
<P>
|
|
|
|
(But see the BUGS section.)
|
|
<P>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>GNU extensions</H3>
|
|
|
|
If the call fails with either
|
|
<B>EACCES</B>
|
|
|
|
or
|
|
<B>ENOENT</B>
|
|
|
|
and
|
|
<I>resolved_path</I>
|
|
|
|
is not NULL, then the prefix of
|
|
<I>path</I>
|
|
|
|
that is not readable or does not exist is returned in
|
|
<I>resolved_path</I>.
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
The POSIX.1-2001 standard version of this function is broken by design,
|
|
since it is impossible to determine a suitable size for the output buffer,
|
|
<I>resolved_path</I>.
|
|
|
|
According to POSIX.1-2001 a buffer of size
|
|
<B>PATH_MAX</B>
|
|
|
|
suffices, but
|
|
<B>PATH_MAX</B>
|
|
|
|
need not be a defined constant, and may have to be obtained using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3).
|
|
|
|
And asking
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3)
|
|
|
|
does not really help, since, on the one hand POSIX warns that
|
|
the result of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3)
|
|
|
|
may be huge and unsuitable for mallocing memory,
|
|
and on the other hand
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3)
|
|
|
|
may return -1 to signify that
|
|
<B>PATH_MAX</B>
|
|
|
|
is not bounded.
|
|
The
|
|
<I>resolved_path == NULL</I>
|
|
|
|
feature, not standardized in POSIX.1-2001,
|
|
but standardized in POSIX.1-2008, allows this design problem to be avoided.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+realpath">realpath</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+readlink">readlink</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+canonicalize_file_name">canonicalize_file_name</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getcwd">getcwd</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+pathconf">pathconf</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sysconf">sysconf</A></B>(3)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="10"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="11"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="12"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="13"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="14"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="15"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="16"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="17"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="18"><A HREF="#lbAJ">GNU extensions</A><DD>
|
|
</DL>
|
|
<DT id="19"><A HREF="#lbAK">BUGS</A><DD>
|
|
<DT id="20"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="21"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:54 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|