217 lines
7.9 KiB
HTML
217 lines
7.9 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>fstat</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="fstat"></a> <a name="tag_03_193"></a><!-- fstat -->
|
|
<!--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_193_01"></a>NAME</h4>
|
|
|
|
<blockquote>fstat - get file status</blockquote>
|
|
|
|
<h4><a name="tag_03_193_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/sys/stat.h.html">sys/stat.h</a>><br>
|
|
<br>
|
|
int fstat(int</tt> <i>fildes</i><tt>, struct stat *</tt><i>buf</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>fstat</i>() function shall obtain information about an open file associated with the file descriptor <i>fildes</i>, and
|
|
shall write it to the area pointed to by <i>buf</i>.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('SHM')">SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If <i>fildes</i> references a shared memory object, the implementation shall update in the <b>stat</b> structure pointed to by the
|
|
<i>buf</i> argument only the <i>st_uid</i>, <i>st_gid</i>, <i>st_size</i>, and <i>st_mode</i> fields, and only the S_IRUSR,
|
|
S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be valid. The implementation may update other fields and
|
|
flags. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If <i>fildes</i> references a typed memory object, the implementation shall update in the <b>stat</b> structure pointed to by the
|
|
<i>buf</i> argument only the <i>st_uid</i>, <i>st_gid</i>, <i>st_size</i>, and <i>st_mode</i> fields, and only the S_IRUSR,
|
|
S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be valid. The implementation may update other fields and
|
|
flags. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>The <i>buf</i> argument is a pointer to a <b>stat</b> structure, as defined in <a href=
|
|
"../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a>, into which information is placed concerning the file.</p>
|
|
|
|
<p>The structure members <i>st_mode</i>, <i>st_ino</i>, <i>st_dev</i>, <i>st_uid</i>, <i>st_gid</i>, <i>st_atime</i>,
|
|
<i>st_ctime</i>, and <i>st_mtime</i> shall have meaningful values for all other file types defined in this volume of
|
|
IEEE Std 1003.1-2001. The value of the member <i>st_nlink</i> shall be set to the number of links to the file.</p>
|
|
|
|
<p>An implementation that provides additional or alternative file access control mechanisms may, under implementation-defined
|
|
conditions, cause <i>fstat</i>() to fail.</p>
|
|
|
|
<p>The <i>fstat</i>() function shall update any time-related fields as described in the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap04.html#tag_04_07">Section 4.7, File Times Update</a>, before writing
|
|
into the <b>stat</b> structure.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and <i>errno</i> set to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>fstat</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EBADF]</dt>
|
|
|
|
<dd>The <i>fildes</i> argument is not a valid file descriptor.</dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while reading from the file system.</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>fstat</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EOVERFLOW]</dt>
|
|
|
|
<dd>One of the values 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_193_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_193_06_01"></a>Obtaining File Status Information</h5>
|
|
|
|
<p>The following example shows how to obtain file status information for a file named <b>/home/cnd/mod1</b>. The structure variable
|
|
<i>buffer</i> is defined for the <b>stat</b> structure. The <b>/home/cnd/mod1</b> file is opened with read/write privileges and is
|
|
passed to the open file descriptor <i>fildes</i>.</p>
|
|
|
|
<pre>
|
|
<tt>#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
<br>
|
|
struct stat buffer;
|
|
int status;
|
|
...
|
|
fildes = open("/home/cnd/mod1", O_RDWR);
|
|
status = fstat(fildes, &buffer);
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="lstat.html"><i>lstat</i>()</a> , <a href="stat.html"><i>stat</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a>, <a href=
|
|
"../basedefs/sys/types.h.html"><i><sys/types.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated for alignment with the POSIX Realtime Extension.</p>
|
|
|
|
<p>Large File Summit extensions are added.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_193_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>In the SYNOPSIS, the optional include of the <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> header is
|
|
removed.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> has been removed. Although <a
|
|
href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> was required for conforming implementations of previous POSIX
|
|
specifications, it was not required for UNIX applications.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EIO] mandatory error condition is added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EOVERFLOW] mandatory error condition is added. This change is to support large files.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [EOVERFLOW] optional error condition is added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The DESCRIPTION is updated for alignment with IEEE Std 1003.1j-2000 by specifying that shared memory object semantics
|
|
apply to typed memory objects.</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>
|
|
|