228 lines
7.5 KiB
HTML
228 lines
7.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>readlink</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
|
|
<basefont size="3"> <a name="readlink"></a> <a name="tag_03_596"></a><!-- readlink -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_596_01"></a>NAME</h4>
|
|
|
|
<blockquote>readlink - read the contents of a symbolic link</blockquote>
|
|
|
|
<h4><a name="tag_03_596_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br>
|
|
<br>
|
|
ssize_t readlink(const char *restrict</tt> <i>path</i><tt>, char *restrict</tt> <i>buf</i><tt>,<br>
|
|
size_t</tt> <i>bufsize</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>readlink</i>() function shall place the contents of the symbolic link referred to by <i>path</i> in the buffer <i>buf</i>
|
|
which has size <i>bufsize</i>. If the number of bytes in the symbolic link is less than <i>bufsize</i>, the contents of the
|
|
remainder of <i>buf</i> are unspecified. If the <i>buf</i> argument is not large enough to contain the link content, the first
|
|
<i>bufsize</i> bytes shall be placed in <i>buf</i>.</p>
|
|
|
|
<p>If the value of <i>bufsize</i> is greater than {SSIZE_MAX}, the result is implementation-defined.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>readlink</i>() shall return the count of bytes placed in the buffer. Otherwise, it shall return a
|
|
value of -1, leave the buffer unchanged, and set <i>errno</i> to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>readlink</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>Search permission is denied for a component of the path prefix of <i>path</i>.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The <i>path</i> argument names a file that is not a symbolic link.</dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while reading from the file system.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
The length of the <i>path</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
|
|
|
|
<dt>[ENOENT]</dt>
|
|
|
|
<dd>A component of <i>path</i> does not name an existing file or <i>path</i> is an empty string.</dd>
|
|
|
|
<dt>[ENOTDIR]</dt>
|
|
|
|
<dd>A component of the path prefix is not a directory.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>readlink</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>Read permission is denied for the directory.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
As a result of encountering a symbolic link in resolution of the <i>path</i> argument, the length of the substituted pathname
|
|
string exceeded {PATH_MAX}.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_596_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_596_06_01"></a>Reading the Name of a Symbolic Link</h5>
|
|
|
|
<p>The following example shows how to read the name of a symbolic link named <b>/modules/pass1</b>.</p>
|
|
|
|
<pre>
|
|
<tt>#include <unistd.h>
|
|
<br>
|
|
char buf[1024];
|
|
ssizet_t len;
|
|
...
|
|
if ((len = readlink("/modules/pass1", buf, sizeof(buf)-1)) != -1)
|
|
buf[len] = '\0';
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>Conforming applications should not assume that the returned contents of the symbolic link are null-terminated.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>Since IEEE Std 1003.1-2001 does not require any association of file times with symbolic links, there is no requirement
|
|
that file times be updated by <i>readlink</i>(). The type associated with <i>bufsiz</i> is a <b>size_t</b> in order to be
|
|
consistent with both the ISO C standard and the definition of <a href="../functions/read.html"><i>read</i>()</a>. The behavior
|
|
specified for <i>readlink</i>() when <i>bufsiz</i> is zero represents historical practice. For this case, the standard developers
|
|
considered a change whereby <i>readlink</i>() would return the number of non-null bytes contained in the symbolic link with the
|
|
buffer <i>buf</i> remaining unchanged; however, since the <b>stat</b> structure member <i>st_size</i> value can be used to
|
|
determine the size of buffer necessary to contain the contents of the symbolic link as returned by <i>readlink</i>(), this proposal
|
|
was rejected, and the historical practice retained.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="lstat.html"><i>lstat</i>()</a> , <a href="stat.html"><i>stat</i>()</a> , <a href="symlink.html"><i>symlink</i>()</a> ,
|
|
the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 4, Version 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>Moved from X/OPEN UNIX extension to BASE.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_596_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The return type is changed to <b>ssize_t</b>, to align with the IEEE P1003.1a draft standard.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>This function is made mandatory.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>In this function it is possible for the return value to exceed the range of the type <b>ssize_t</b> (since <b>size_t</b> has a
|
|
larger range of positive values than <b>ssize_t</b>). A sentence restricting the size of the <b>size_t</b> object is added to the
|
|
description to resolve this conflict.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes are made for alignment with the ISO POSIX-1:1996 standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The FUTURE DIRECTIONS section is changed to None.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes were made to align with the IEEE P1003.1a draft standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The [ELOOP] optional error condition is added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The <b>restrict</b> keyword is added to the <i>readlink</i>() prototype for alignment with the ISO/IEC 9899:1999
|
|
standard.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|