REALPATH(3)                POSIX Programmer's Manual               REALPATH(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       realpath -- resolve a pathname

SSYYNNOOPPSSIISS
       #include <stdlib.h>

       char *realpath(const char *restrict _f_i_l_e___n_a_m_e,
           char *restrict _r_e_s_o_l_v_e_d___n_a_m_e);

DDEESSCCRRIIPPTTIIOONN
       The _r_e_a_l_p_a_t_h() function shall derive, from the pathname pointed to by
       _f_i_l_e___n_a_m_e, an absolute pathname that resolves to the same directory
       entry, whose resolution does not involve ''..'', ''....'', or symbolic links.
       If _r_e_s_o_l_v_e_d___n_a_m_e is a null pointer, the generated pathname shall be
       stored as a null-terminated string in a buffer allocated as if by a
       call to _m_a_l_l_o_c().  Otherwise, if {PATH_MAX} is defined as a constant in
       the _<_l_i_m_i_t_s_._h_> header, then the generated pathname shall be stored as a
       null-terminated string, up to a maximum of {PATH_MAX} bytes, in the
       buffer pointed to by _r_e_s_o_l_v_e_d___n_a_m_e.

       If _r_e_s_o_l_v_e_d___n_a_m_e is not a null pointer and {PATH_MAX} is not defined as
       a constant in the _<_l_i_m_i_t_s_._h_> header, the behavior is undefined.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _r_e_a_l_p_a_t_h() shall return a pointer to the
       buffer containing the resolved name.  Otherwise, _r_e_a_l_p_a_t_h() shall
       return a null pointer and set _e_r_r_n_o to indicate the error.

       If the _r_e_s_o_l_v_e_d___n_a_m_e argument is a null pointer, the pointer returned
       by _r_e_a_l_p_a_t_h() can be passed to _f_r_e_e().

       If the _r_e_s_o_l_v_e_d___n_a_m_e argument is not a null pointer and the _r_e_a_l_p_a_t_h()
       function fails, the contents of the buffer pointed to by _r_e_s_o_l_v_e_d___n_a_m_e
       are undefined.

EERRRROORRSS
       The _r_e_a_l_p_a_t_h() function shall fail if:

       EEAACCCCEESS Search permission was denied for a component of the path prefix
              of _f_i_l_e___n_a_m_e.

       EEIINNVVAALL The _f_i_l_e___n_a_m_e argument is a null pointer.

       EEIIOO    An error occurred while reading from the file system.

       EELLOOOOPP  A loop exists in symbolic links encountered during resolution of
              the _f_i_l_e___n_a_m_e argument.

       EENNAAMMEETTOOOOLLOONNGG
              The length of a component of a pathname is longer than
              {NAME_MAX}.

       EENNOOEENNTT A component of _f_i_l_e___n_a_m_e does not name an existing file or
              _f_i_l_e___n_a_m_e points to an empty string.

       EENNOOTTDDIIRR
              A component of the path prefix names an existing file that is
              neither a directory nor a symbolic link to a directory, or the
              _f_i_l_e___n_a_m_e argument contains at least one non-<slash> character
              and ends with one or more trailing <slash> characters and the
              last pathname component names an existing file that is neither a
              directory nor a symbolic link to a directory.

       The _r_e_a_l_p_a_t_h() function may fail if:

       EEAACCCCEESS The _f_i_l_e___n_a_m_e argument does not begin with a <slash> and none of
              the symbolic links (if any) processed during pathname resolution
              of _f_i_l_e___n_a_m_e had contents that began with a <slash>, and either
              search permission was denied for the current directory or read
              or search permission was denied for a directory above the
              current directory in the file hierarchy.

       EELLOOOOPP  More than {SYMLOOP_MAX} symbolic links were encountered during
              resolution of the _f_i_l_e___n_a_m_e argument.

       EENNAAMMEETTOOOOLLOONNGG
              The length of a pathname exceeds {PATH_MAX}, or pathname
              resolution of a symbolic link produced an intermediate result
              with a length that exceeds {PATH_MAX}.

       EENNOOMMEEMM Insufficient storage space is available.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   GGeenneerraattiinngg aann AAbbssoolluuttee PPaatthhnnaammee
       The following example generates an absolute pathname for the file
       identified by the _s_y_m_l_i_n_k_p_a_t_h argument. The generated pathname is
       stored in the buffer pointed to by _a_c_t_u_a_l_p_a_t_h.


           #include <stdlib.h>
           ...
           char *symlinkpath = "/tmp/symlink/file";
           char *actualpath;

           actualpath = realpath(symlinkpath, NULL);
           if (actualpath != NULL)
           {
               ... use actualpath ...

               free(actualpath);
           }
           else
           {
               ... handle error ...
           }

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       For functions that allocate memory as if by _m_a_l_l_o_c(), the application
       should release such memory when it is no longer required by a call to
       _f_r_e_e().  For _r_e_a_l_p_a_t_h(), this is the return value.

RRAATTIIOONNAALLEE
       Since _r_e_a_l_p_a_t_h() has no _l_e_n_g_t_h argument, if {PATH_MAX} is not defined
       as a constant in _<_l_i_m_i_t_s_._h_>, applications have no way of determining
       how large a buffer they need to allocate for it to be safe to pass to
       _r_e_a_l_p_a_t_h().  A {PATH_MAX} value obtained from a prior _p_a_t_h_c_o_n_f() call
       is out-of-date by the time _r_e_a_l_p_a_t_h() is called. Hence the only
       reliable way to use _r_e_a_l_p_a_t_h() when {PATH_MAX} is not defined in
       _<_l_i_m_i_t_s_._h_> is to pass a null pointer for _r_e_s_o_l_v_e_d___n_a_m_e so that
       _r_e_a_l_p_a_t_h() will allocate a buffer of the necessary size.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _f_p_a_t_h_c_o_n_f(), _f_r_e_e(), _g_e_t_c_w_d(), _s_y_s_c_o_n_f()

       The Base Definitions volume of POSIX.1-2017, <<lliimmiittss..hh>>, <<ssttddlliibb..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                          REALPATH(3)
