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

225 lines
8.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>ftruncate</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="ftruncate"></a> <a name="tag_03_199"></a><!-- ftruncate -->
<!--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_199_01"></a>NAME</h4>
<blockquote>ftruncate - truncate a file to a specified length</blockquote>
<h4><a name="tag_03_199_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br>
<br>
int ftruncate(int</tt> <i>fildes</i><tt>, off_t</tt> <i>length</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_199_03"></a>DESCRIPTION</h4>
<blockquote>
<p>If <i>fildes</i> is not a valid file descriptor open for writing, the <i>ftruncate</i>() function shall fail.</p>
<p>If <i>fildes</i> refers to a regular file, the <i>ftruncate</i>() function shall cause the size of the file to be truncated to
<i>length</i>. If the size of the file previously exceeded <i>length</i>, the extra data shall no longer be available to reads on
the file. If the file previously was smaller than this size, <i>ftruncate</i>() shall either increase the size of the file or fail.
<sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
&nbsp;XSI-conformant systems shall increase the size of the file. <img src="../images/opt-end.gif" alt="[Option End]" border="0">
If the file size is increased, the extended area shall appear as if it were zero-filled. The value of the seek pointer shall not be
modified by a call to <i>ftruncate</i>().</p>
<p>Upon successful completion, if <i>fildes</i> refers to a regular file, the <i>ftruncate</i>() function shall mark for update the
<i>st_ctime</i> and <i>st_mtime</i> fields of the file and the S_ISUID and S_ISGID bits of the file mode may be cleared. If the
<i>ftruncate</i>() function is unsuccessful, the file is unaffected.</p>
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If the request would cause the file size to exceed the soft file size limit for the process, the request shall fail and the
implementation shall generate the SIGXFSZ signal for the thread. <img src="../images/opt-end.gif" alt="[Option End]" border=
"0"></p>
<p>If <i>fildes</i> refers to a directory, <i>ftruncate</i>() shall fail.</p>
<p>If <i>fildes</i> refers to any other file type, except a shared memory object, the result is unspecified.</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> refers to a shared memory object, <i>ftruncate</i>() shall set the size of the shared memory object to
<i>length</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
<p><sup>[<a href="javascript:open_code('MF')">MF|SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If the effect of <i>ftruncate</i>() is to decrease the size of a shared memory object or memory mapped file and whole pages beyond
the new end were previously mapped, then the whole pages beyond the new end shall be discarded. <img src="../images/opt-end.gif"
alt="[Option End]" border="0"></p>
<p><sup>[<a href="javascript:open_code('MPR')">MPR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If the Memory Protection option is supported, references to discarded pages shall result in the generation of a SIGBUS signal;
otherwise, the result of such references is undefined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
<p><sup>[<a href="javascript:open_code('MF')">MF|SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
If the effect of <i>ftruncate</i>() is to increase the size of a shared memory object, it is unspecified whether the contents of
any mapped pages between the old end-of-file and the new are flushed to the underlying object. <img src="../images/opt-end.gif"
alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_03_199_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>ftruncate</i>() shall return 0; otherwise, -1 shall be returned and <i>errno</i> set to indicate
the error.</p>
</blockquote>
<h4><a name="tag_03_199_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>ftruncate</i>() function shall fail if:</p>
<dl compact>
<dt>[EINTR]</dt>
<dd>A signal was caught during execution.</dd>
<dt>[EINVAL]</dt>
<dd>The <i>length</i> argument was less than 0.</dd>
<dt>[EFBIG] or [EINVAL]</dt>
<dd><br>
The <i>length</i> argument was greater than the maximum file size.</dd>
<dt>[EFBIG]</dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
The file is a regular file and <i>length</i> is greater than the offset maximum established in the open file description associated
with <i>fildes</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
<dt>[EIO]</dt>
<dd>An I/O error occurred while reading from or writing to a file system.</dd>
<dt>[EBADF] or [EINVAL]</dt>
<dd><br>
The <i>fildes</i> argument is not a file descriptor open for writing.</dd>
<dt>[EINVAL]</dt>
<dd>The <i>fildes</i> argument references a file that was opened without write permission.</dd>
<dt>[EROFS]</dt>
<dd>The named file resides on a read-only file system.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_199_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_199_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_199_08"></a>RATIONALE</h4>
<blockquote>
<p>The <i>ftruncate</i>() function is part of IEEE&nbsp;Std&nbsp;1003.1-2001 as it was deemed to be more useful than <a href=
"../functions/truncate.html"><i>truncate</i>()</a>. The <a href="../functions/truncate.html"><i>truncate</i>()</a> function is
provided as an XSI extension.</p>
</blockquote>
<h4><a name="tag_03_199_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_199_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="open.html"><i>open</i>()</a> , <a href="truncate.html"><i>truncate</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_199_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_199_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE and aligned with <i>ftruncate</i>() in the POSIX Realtime Extension. Specifically, the
DESCRIPTION is extensively reworded and [EROFS] is added to the list of mandatory errors that can be returned by
<i>ftruncate</i>().</p>
<p>Large File Summit extensions are added.</p>
</blockquote>
<h4><a name="tag_03_199_13"></a>Issue 6</h4>
<blockquote>
<p>The <a href="../functions/truncate.html"><i>truncate</i>()</a> function has been split out into a separate reference page.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The DESCRIPTION is changed to indicate that if the file size is changed, and if the file is a regular file, the S_ISUID and
S_ISGID bits in the file mode may be cleared.</p>
</li>
</ul>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>The DESCRIPTION text is updated.</p>
</li>
</ul>
<p>XSI-conformant systems are required to increase the size of the file if the file was previously smaller than the size
requested.</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>