1REALPATH(3P)               POSIX Programmer's Manual              REALPATH(3P)
2
3
4

PROLOG

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

NAME

12       realpath — resolve a pathname
13

SYNOPSIS

15       #include <stdlib.h>
16
17       char *realpath(const char *restrict file_name,
18           char *restrict resolved_name);
19

DESCRIPTION

21       The realpath() function shall derive, from the pathname pointed  to  by
22       file_name,  an  absolute  pathname  that resolves to the same directory
23       entry, whose resolution does not involve '.', '..', or symbolic  links.
24       If  resolved_name  is  a  null pointer, the generated pathname shall be
25       stored as a null-terminated string in a buffer allocated  as  if  by  a
26       call to malloc().  Otherwise, if {PATH_MAX} is defined as a constant in
27       the <limits.h> header, then the generated pathname shall be stored as a
28       null-terminated  string,  up  to  a maximum of {PATH_MAX} bytes, in the
29       buffer pointed to by resolved_name.
30
31       If resolved_name is not a null pointer and {PATH_MAX} is not defined as
32       a constant in the <limits.h> header, the behavior is undefined.
33

RETURN VALUE

35       Upon  successful  completion,  realpath() shall return a pointer to the
36       buffer containing  the  resolved  name.   Otherwise,  realpath()  shall
37       return a null pointer and set errno to indicate the error.
38
39       If  the  resolved_name argument is a null pointer, the pointer returned
40       by realpath() can be passed to free().
41
42       If the resolved_name argument is not a null pointer and the  realpath()
43       function  fails, the contents of the buffer pointed to by resolved_name
44       are undefined.
45

ERRORS

47       The realpath() function shall fail if:
48
49       EACCES Search permission was denied for a component of the path  prefix
50              of file_name.
51
52       EINVAL The file_name argument is a null pointer.
53
54       EIO    An error occurred while reading from the file system.
55
56       ELOOP  A loop exists in symbolic links encountered during resolution of
57              the file_name argument.
58
59       ENAMETOOLONG
60              The  length  of  a  component  of  a  pathname  is  longer  than
61              {NAME_MAX}.
62
63       ENOENT A  component  of  file_name  does  not  name an existing file or
64              file_name points to an empty string.
65
66       ENOTDIR
67              A component of the path prefix names an existing  file  that  is
68              neither  a  directory nor a symbolic link to a directory, or the
69              file_name argument contains at least one  non-<slash>  character
70              and  ends  with  one or more trailing <slash> characters and the
71              last pathname component names an existing file that is neither a
72              directory nor a symbolic link to a directory.
73
74       The realpath() function may fail if:
75
76       EACCES The file_name argument does not begin with a <slash> and none of
77              the symbolic links (if any) processed during pathname resolution
78              of  file_name had contents that began with a <slash>, and either
79              search permission was denied for the current directory  or  read
80              or  search  permission was denied for a directory above the cur‐
81              rent directory in the file hierarchy.
82
83       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
84              resolution of the file_name argument.
85
86       ENAMETOOLONG
87              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
88              tion of a symbolic link produced an intermediate result  with  a
89              length that exceeds {PATH_MAX}.
90
91       ENOMEM Insufficient storage space is available.
92
93       The following sections are informative.
94

EXAMPLES

96   Generating an Absolute Pathname
97       The following example generates an absolute pathname for the file iden‐
98       tified by the symlinkpath argument. The generated pathname is stored in
99       the buffer pointed to by actualpath.
100
101
102           #include <stdlib.h>
103           ...
104           char *symlinkpath = "/tmp/symlink/file";
105           char *actualpath;
106
107           actualpath = realpath(symlinkpath, NULL);
108           if (actualpath != NULL)
109           {
110               ... use actualpath ...
111
112               free(actualpath);
113           }
114           else
115           {
116               ... handle error ...
117           }
118

APPLICATION USAGE

120       For  functions  that allocate memory as if by malloc(), the application
121       should release such memory when it is no longer required by a  call  to
122       free().  For realpath(), this is the return value.
123

RATIONALE

125       Since  realpath()  has no length argument, if {PATH_MAX} is not defined
126       as a constant in <limits.h>, applications have no  way  of  determining
127       how  large  a buffer they need to allocate for it to be safe to pass to
128       realpath().  A {PATH_MAX} value obtained from a prior  pathconf()  call
129       is  out-of-date  by the time realpath() is called. Hence the only reli‐
130       able way to use realpath() when {PATH_MAX} is not defined in <limits.h>
131       is  to  pass  a  null pointer for resolved_name so that realpath() will
132       allocate a buffer of the necessary size.
133

FUTURE DIRECTIONS

135       None.
136

SEE ALSO

138       fpathconf(), free(), getcwd(), sysconf()
139
140       The Base Definitions volume of POSIX.1‐2017, <limits.h>, <stdlib.h>
141
143       Portions of this text are reprinted and reproduced in  electronic  form
144       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
145       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
146       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
147       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
148       event of any discrepancy between this version and the original IEEE and
149       The Open Group Standard, the original IEEE and The Open Group  Standard
150       is  the  referee document. The original Standard can be obtained online
151       at http://www.opengroup.org/unix/online.html .
152
153       Any typographical or formatting errors that appear  in  this  page  are
154       most likely to have been introduced during the conversion of the source
155       files to man page format. To report such errors,  see  https://www.ker
156       nel.org/doc/man-pages/reporting_bugs.html .
157
158
159
160IEEE/The Open Group                  2017                         REALPATH(3P)
Impressum