Blame man-pages-posix-2013-a/man3p/realpath.3p

Packit 7cfc04
'\" et
Packit 7cfc04
.TH REALPATH "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
Packit 7cfc04
.SH PROLOG
Packit 7cfc04
This manual page is part of the POSIX Programmer's Manual.
Packit 7cfc04
The Linux implementation of this interface may differ (consult
Packit 7cfc04
the corresponding Linux manual page for details of Linux behavior),
Packit 7cfc04
or the interface may not be implemented on Linux.
Packit 7cfc04
Packit 7cfc04
.SH NAME
Packit 7cfc04
realpath
Packit 7cfc04
\(em resolve a pathname
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
.P
Packit 7cfc04
char *realpath(const char *restrict \fIfile_name\fP,
Packit 7cfc04
    char *restrict \fIresolved_name\fP);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
function shall derive, from the pathname pointed to by
Packit 7cfc04
.IR file_name ,
Packit 7cfc04
an absolute pathname that resolves to the same directory entry, whose
Packit 7cfc04
resolution does not involve
Packit 7cfc04
.BR '.' ,
Packit 7cfc04
.BR '..' ,
Packit 7cfc04
or symbolic links. If
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
is a null pointer, the generated pathname shall be stored as a
Packit 7cfc04
null-terminated string in a buffer allocated as if by a call to
Packit 7cfc04
\fImalloc\fR().
Packit 7cfc04
Otherwise, if
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
is defined as a constant in the
Packit 7cfc04
.IR <limits.h> 
Packit 7cfc04
header, then the generated pathname shall be stored as a null-terminated
Packit 7cfc04
string, up to a maximum of
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
bytes, in the buffer pointed to by
Packit 7cfc04
.IR resolved_name .
Packit 7cfc04
.P
Packit 7cfc04
If
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
is not a null pointer and
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
is not defined as a constant in the
Packit 7cfc04
.IR <limits.h> 
Packit 7cfc04
header, the behavior is undefined.
Packit 7cfc04
.SH "RETURN VALUE"
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
shall return a pointer to the buffer containing the resolved name.
Packit 7cfc04
Otherwise,
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
shall return a null pointer and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.P
Packit 7cfc04
If the
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
argument is a null pointer, the pointer returned by
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
can be passed to
Packit 7cfc04
\fIfree\fR().
Packit 7cfc04
.P
Packit 7cfc04
If the
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
argument is not a null pointer and the
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
function fails, the contents of the buffer pointed to by
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
are undefined.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
The
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
function shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES
Packit 7cfc04
Search permission was denied for a component of the path prefix of
Packit 7cfc04
.IR file_name .
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL
Packit 7cfc04
The
Packit 7cfc04
.IR file_name
Packit 7cfc04
argument is a null pointer.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EIO
Packit 7cfc04
An error occurred while reading from the file system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ELOOP
Packit 7cfc04
A loop exists in symbolic links encountered during resolution of the
Packit 7cfc04
.IR file_name
Packit 7cfc04
argument.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENAMETOOLONG
Packit 7cfc04
.br
Packit 7cfc04
The length of a component of a pathname is longer than
Packit 7cfc04
{NAME_MAX}.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOENT
Packit 7cfc04
A component of
Packit 7cfc04
.IR file_name
Packit 7cfc04
does not name an existing file or
Packit 7cfc04
.IR file_name
Packit 7cfc04
points to an empty string.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOTDIR
Packit 7cfc04
A component of the path prefix names an existing file that is neither
Packit 7cfc04
a directory nor a symbolic link to a directory, or the
Packit 7cfc04
.IR file_name
Packit 7cfc04
argument contains at least one non-\c
Packit 7cfc04
<slash>
Packit 7cfc04
character and ends with one or more trailing
Packit 7cfc04
<slash>
Packit 7cfc04
characters and the last pathname component names an existing file that
Packit 7cfc04
is neither a directory nor a symbolic link to a directory.
Packit 7cfc04
.br
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
function may fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES
Packit 7cfc04
The
Packit 7cfc04
.IR file_name
Packit 7cfc04
argument does not begin with a
Packit 7cfc04
<slash>
Packit 7cfc04
and none of the symbolic links (if any) processed during pathname
Packit 7cfc04
resolution of
Packit 7cfc04
.IR file_name
Packit 7cfc04
had contents that began with a
Packit 7cfc04
<slash>,
Packit 7cfc04
and either search permission was denied for the current directory or
Packit 7cfc04
read or search permission was denied for a directory above the current
Packit 7cfc04
directory in the file hierarchy.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ELOOP
Packit 7cfc04
More than
Packit 7cfc04
{SYMLOOP_MAX}
Packit 7cfc04
symbolic links were encountered during resolution of the
Packit 7cfc04
.IR file_name
Packit 7cfc04
argument.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENAMETOOLONG
Packit 7cfc04
.br
Packit 7cfc04
The length of a pathname exceeds
Packit 7cfc04
{PATH_MAX},
Packit 7cfc04
or pathname resolution of a symbolic link produced an intermediate
Packit 7cfc04
result with a length that exceeds
Packit 7cfc04
{PATH_MAX}.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOMEM
Packit 7cfc04
Insufficient storage space is available.
Packit 7cfc04
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH EXAMPLES
Packit 7cfc04
.SS "Generating an Absolute Pathname"
Packit 7cfc04
.P
Packit 7cfc04
The following example generates an absolute pathname for the file
Packit 7cfc04
identified by the
Packit 7cfc04
.IR symlinkpath
Packit 7cfc04
argument. The generated pathname is stored in the buffer pointed to by
Packit 7cfc04
.IR actualpath .
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
\&...
Packit 7cfc04
char *symlinkpath = "/tmp/symlink/file";
Packit 7cfc04
char *actualpath;
Packit 7cfc04
.P
Packit 7cfc04
actualpath = realpath(symlinkpath, NULL);
Packit 7cfc04
if (actualpath != NULL)
Packit 7cfc04
{
Packit 7cfc04
    ... use actualpath ...
Packit 7cfc04
.P
Packit 7cfc04
    free(actualpath);
Packit 7cfc04
}
Packit 7cfc04
else
Packit 7cfc04
{
Packit 7cfc04
    ... handle error ...
Packit 7cfc04
}
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
For functions that allocate memory as if by
Packit 7cfc04
\fImalloc\fR(),
Packit 7cfc04
the application should release such memory when it is no longer
Packit 7cfc04
required by a call to
Packit 7cfc04
\fIfree\fR().
Packit 7cfc04
For
Packit 7cfc04
\fIrealpath\fR(),
Packit 7cfc04
this is the return value.
Packit 7cfc04
.SH RATIONALE
Packit 7cfc04
Since
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
has no
Packit 7cfc04
.IR length
Packit 7cfc04
argument, if
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
is not defined as a constant in
Packit 7cfc04
.IR <limits.h> ,
Packit 7cfc04
applications have no way of determining how large a buffer they need
Packit 7cfc04
to allocate for it to be safe to pass to
Packit 7cfc04
\fIrealpath\fR().
Packit 7cfc04
A
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
value obtained from a prior
Packit 7cfc04
\fIpathconf\fR()
Packit 7cfc04
call is out-of-date by the time
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
is called. Hence the only reliable way to use
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
when
Packit 7cfc04
{PATH_MAX}
Packit 7cfc04
is not defined in
Packit 7cfc04
.IR <limits.h> 
Packit 7cfc04
is to pass a null pointer for
Packit 7cfc04
.IR resolved_name
Packit 7cfc04
so that
Packit 7cfc04
\fIrealpath\fR()
Packit 7cfc04
will allocate a buffer of the necessary size.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
None.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "\fIfpathconf\fR\^(\|)",
Packit 7cfc04
.IR "\fIfree\fR\^(\|)",
Packit 7cfc04
.IR "\fIgetcwd\fR\^(\|)",
Packit 7cfc04
.IR "\fIsysconf\fR\^(\|)"
Packit 7cfc04
.P
Packit 7cfc04
The Base Definitions volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "\fB<limits.h>\fP",
Packit 7cfc04
.IR "\fB<stdlib.h>\fP"
Packit 7cfc04
.SH COPYRIGHT
Packit 7cfc04
Portions of this text are reprinted and reproduced in electronic form
Packit 7cfc04
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
Packit 7cfc04
-- Portable Operating System Interface (POSIX), The Open Group Base
Packit 7cfc04
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Packit 7cfc04
Electrical and Electronics Engineers, Inc and The Open Group.
Packit 7cfc04
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
Packit 7cfc04
event of any discrepancy between this version and the original IEEE and
Packit 7cfc04
The Open Group Standard, the original IEEE and The Open Group Standard
Packit 7cfc04
is the referee document. The original Standard can be obtained online at
Packit 7cfc04
http://www.unix.org/online.html .
Packit 7cfc04
Packit 7cfc04
Any typographical or formatting errors that appear
Packit 7cfc04
in this page are most likely
Packit 7cfc04
to have been introduced during the conversion of the source files to
Packit 7cfc04
man page format. To report such errors, see
Packit 7cfc04
https://www.kernel.org/doc/man-pages/reporting_bugs.html .