Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/lstat.html
2024-02-19 00:21:47 -05:00

210 lines
6.8 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>lstat</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="lstat"></a> <a name="tag_03_355"></a><!-- lstat -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_355_01"></a>NAME</h4>
<blockquote>lstat - get symbolic link status</blockquote>
<h4><a name="tag_03_355_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/sys/stat.h.html">sys/stat.h</a>&gt;<br>
<br>
int lstat(const char *restrict</tt> <i>path</i><tt>, struct stat *restrict</tt> <i>buf</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_355_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>lstat</i>() function shall be equivalent to <a href="../functions/stat.html"><i>stat</i>()</a>, except when <i>path</i>
refers to a symbolic link. In that case <i>lstat</i>() shall return information about the link, while <a href=
"../functions/stat.html"><i>stat</i>()</a> shall return information about the file the link references.</p>
<p>For symbolic links, the <i>st_mode</i> member shall contain meaningful information when used with the file type macros, and the
<i>st_size</i> member shall contain the length of the pathname contained in the symbolic link. File mode bits and the contents of
the remaining members of the <b>stat</b> structure are unspecified. The value returned in the <i>st_size</i> member is the length
of the contents of the symbolic link, and does not count any trailing null.</p>
</blockquote>
<h4><a name="tag_03_355_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>lstat</i>() shall return 0. Otherwise, it shall return -1 and set <i>errno</i> to indicate the
error.</p>
</blockquote>
<h4><a name="tag_03_355_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>lstat</i>() function shall fail if:</p>
<dl compact>
<dt>[EACCES]</dt>
<dd>A component of the path prefix denies search permission.</dd>
<dt>[EIO]</dt>
<dd>An 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 a pathname exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
<dt>[ENOTDIR]</dt>
<dd>A component of the path prefix is not a directory.</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>[EOVERFLOW]</dt>
<dd>The file size in bytes or the number of blocks allocated to the file or the file serial number cannot be represented correctly
in the structure pointed to by <i>buf</i>.</dd>
</dl>
<p>The <i>lstat</i>() function may fail if:</p>
<dl compact>
<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>
<dt>[EOVERFLOW]</dt>
<dd>One of the members is too large to store into the structure pointed to by the <i>buf</i> argument.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_355_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_355_06_01"></a>Obtaining Symbolic Link Status Information</h5>
<p>The following example shows how to obtain status information for a symbolic link named <b>/modules/pass1</b>. The structure
variable <i>buffer</i> is defined for the <b>stat</b> structure. If the <i>path</i> argument specified the filename for the file
pointed to by the symbolic link ( <b>/home/cnd/mod1</b>), the results of calling the function would be the same as those returned
by a call to the <a href="../functions/stat.html"><i>stat</i>()</a> function.</p>
<pre>
<tt>#include &lt;sys/stat.h&gt;
<br>
struct stat buffer;
int status;
...
status = lstat("/modules/pass1", &amp;buffer);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_355_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_355_08"></a>RATIONALE</h4>
<blockquote>
<p>The <i>lstat</i>() function is not required to update the time-related fields if the named file is not a symbolic link. While
the <i>st_uid</i>, <i>st_gid</i>, <i>st_atime</i>, <i>st_mtime</i>, and <i>st_ctime</i> members of the <b>stat</b> structure may
apply to a symbolic link, they are not required to do so. No functions in IEEE&nbsp;Std&nbsp;1003.1-2001 are required to maintain
any of these time fields.</p>
</blockquote>
<h4><a name="tag_03_355_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_355_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="fstat.html"><i>fstat</i>()</a> , <a href="readlink.html"><i>readlink</i>()</a> , <a href="stat.html"><i>stat</i>()</a>
, <a href="symlink.html"><i>symlink</i>()</a> , the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/sys/stat.h.html"><i>&lt;sys/stat.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_355_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_355_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
<p>Large File Summit extensions are added.</p>
</blockquote>
<h4><a name="tag_03_355_13"></a>Issue 6</h4>
<blockquote>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>This function is now mandatory.</p>
</li>
<li>
<p>The [ELOOP] optional error condition is added.</p>
</li>
</ul>
<p>The <b>restrict</b> keyword is added to the <i>lstat</i>() prototype for alignment with the ISO/IEC&nbsp;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 &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; 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>