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

Packit 7cfc04
'\" et
Packit 7cfc04
.TH READLINK "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
readlink, readlinkat
Packit 7cfc04
\(em read the contents of a symbolic link
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
.P
Packit 7cfc04
ssize_t readlink(const char *restrict \fIpath\fP, char *restrict \fIbuf\fP,
Packit 7cfc04
    size_t \fIbufsize\fP);
Packit 7cfc04
ssize_t readlinkat(int \fIfd\fP, const char *restrict \fIpath\fP,
Packit 7cfc04
    char *restrict \fIbuf\fP, size_t \fIbufsize\fP);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
\fIreadlink\fR()
Packit 7cfc04
function shall place the contents of the symbolic link referred to by
Packit 7cfc04
.IR path
Packit 7cfc04
in the buffer
Packit 7cfc04
.IR buf
Packit 7cfc04
which has size
Packit 7cfc04
.IR bufsize .
Packit 7cfc04
If the number of bytes in the symbolic link is less than
Packit 7cfc04
.IR bufsize ,
Packit 7cfc04
the contents of the remainder of
Packit 7cfc04
.IR buf
Packit 7cfc04
are unspecified. If the
Packit 7cfc04
.IR buf
Packit 7cfc04
argument is not large enough to contain the link content, the first
Packit 7cfc04
.IR bufsize
Packit 7cfc04
bytes shall be placed in
Packit 7cfc04
.IR buf .
Packit 7cfc04
.P
Packit 7cfc04
If the value of
Packit 7cfc04
.IR bufsize
Packit 7cfc04
is greater than
Packit 7cfc04
{SSIZE_MAX},
Packit 7cfc04
the result is implementation-defined.
Packit 7cfc04
.P
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
\fIreadlink\fR()
Packit 7cfc04
shall mark for update the last data access timestamp of the symbolic
Packit 7cfc04
link.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIreadlinkat\fR()
Packit 7cfc04
function shall be equivalent to the
Packit 7cfc04
\fIreadlink\fR()
Packit 7cfc04
function except in the case where
Packit 7cfc04
.IR path
Packit 7cfc04
specifies a relative path. In this case the symbolic link whose content
Packit 7cfc04
is read is relative to the directory associated with the file
Packit 7cfc04
descriptor
Packit 7cfc04
.IR fd
Packit 7cfc04
instead of the current working directory. If the file descriptor was
Packit 7cfc04
opened without O_SEARCH, the function shall check whether directory
Packit 7cfc04
searches are permitted using the current permissions of the directory
Packit 7cfc04
underlying the file descriptor. If the file descriptor was opened with
Packit 7cfc04
O_SEARCH, the function shall not perform the check.
Packit 7cfc04
.P
Packit 7cfc04
If
Packit 7cfc04
\fIreadlinkat\fR()
Packit 7cfc04
is passed the special value AT_FDCWD in the
Packit 7cfc04
.IR fd
Packit 7cfc04
parameter, the current working directory shall be used and the behavior
Packit 7cfc04
shall be identical to a call to
Packit 7cfc04
\fIreadlink\fR().
Packit 7cfc04
.SH "RETURN VALUE"
Packit 7cfc04
Upon successful completion, these functions shall return the count of
Packit 7cfc04
bytes placed in the buffer. Otherwise, these functions shall return a
Packit 7cfc04
value of \(mi1, leave the buffer unchanged, and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
These functions shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES
Packit 7cfc04
Search permission is denied for a component of the path prefix of
Packit 7cfc04
.IR path .
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL
Packit 7cfc04
The
Packit 7cfc04
.IR path
Packit 7cfc04
argument names a file that is not a symbolic link.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EIO
Packit 7cfc04
An I/O 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 path
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 path
Packit 7cfc04
does not name an existing file or
Packit 7cfc04
.IR path
Packit 7cfc04
is 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 path
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
\fIreadlinkat\fR()
Packit 7cfc04
function shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EACCES
Packit 7cfc04
.IR fd
Packit 7cfc04
was not opened with O_SEARCH and the permissions of the directory
Packit 7cfc04
underlying
Packit 7cfc04
.IR fd
Packit 7cfc04
do not permit directory searches.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EBADF
Packit 7cfc04
The
Packit 7cfc04
.IR path
Packit 7cfc04
argument does not specify an absolute path and the
Packit 7cfc04
.IR fd
Packit 7cfc04
argument is neither AT_FDCWD nor a valid file descriptor open for reading
Packit 7cfc04
or searching.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOTDIR
Packit 7cfc04
The
Packit 7cfc04
.IR path
Packit 7cfc04
argument is not an absolute path and
Packit 7cfc04
.IR fd
Packit 7cfc04
is a file descriptor associated with a non-directory file.
Packit 7cfc04
.P
Packit 7cfc04
These functions may fail if:
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 path
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
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH EXAMPLES
Packit 7cfc04
.SS "Reading the Name of a Symbolic Link"
Packit 7cfc04
.P
Packit 7cfc04
The following example shows how to read the name of a symbolic link
Packit 7cfc04
named
Packit 7cfc04
.BR /modules/pass1 .
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
.P
Packit 7cfc04
char buf[1024];
Packit 7cfc04
ssize_t len;
Packit 7cfc04
\&...
Packit 7cfc04
if ((len = readlink("/modules/pass1", buf, sizeof(buf)-1)) != -1)
Packit 7cfc04
    buf[len] = '\e0';
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
Conforming applications should not assume that the returned contents of
Packit 7cfc04
the symbolic link are null-terminated.
Packit 7cfc04
.SH RATIONALE
Packit 7cfc04
The type associated with
Packit 7cfc04
.IR bufsiz
Packit 7cfc04
is a
Packit 7cfc04
.BR size_t
Packit 7cfc04
in order to be consistent with both the ISO\ C standard and the definition of
Packit 7cfc04
\fIread\fR().
Packit 7cfc04
The behavior specified for
Packit 7cfc04
\fIreadlink\fR()
Packit 7cfc04
when
Packit 7cfc04
.IR bufsiz
Packit 7cfc04
is zero represents historical practice. For this case, the standard
Packit 7cfc04
developers considered a change whereby
Packit 7cfc04
\fIreadlink\fR()
Packit 7cfc04
would return the number of non-null bytes contained in the symbolic
Packit 7cfc04
link with the buffer
Packit 7cfc04
.IR buf
Packit 7cfc04
remaining unchanged; however, since the
Packit 7cfc04
.BR stat
Packit 7cfc04
structure member
Packit 7cfc04
.IR st_size
Packit 7cfc04
value can be used to determine the size of buffer necessary to contain
Packit 7cfc04
the contents of the symbolic link as returned by
Packit 7cfc04
\fIreadlink\fR(),
Packit 7cfc04
this proposal was rejected, and the historical practice retained.
Packit 7cfc04
.P
Packit 7cfc04
The purpose of the
Packit 7cfc04
\fIreadlinkat\fR()
Packit 7cfc04
function is to read the content of symbolic links in directories other
Packit 7cfc04
than the current working directory without exposure to race conditions.
Packit 7cfc04
Any part of the path of a file could be changed in parallel to a call
Packit 7cfc04
to
Packit 7cfc04
\fIreadlink\fR(),
Packit 7cfc04
resulting in unspecified behavior. By opening a file descriptor for
Packit 7cfc04
the target directory and using the
Packit 7cfc04
\fIreadlinkat\fR()
Packit 7cfc04
function it can be guaranteed that the symbolic link read is located
Packit 7cfc04
relative to the desired directory.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
None.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "\fIfstatat\fR\^(\|)",
Packit 7cfc04
.IR "\fIsymlink\fR\^(\|)"
Packit 7cfc04
.P
Packit 7cfc04
The Base Definitions volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "\fB<unistd.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 .