205 lines
6.2 KiB
HTML
205 lines
6.2 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>truncate</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="truncate"></a> <a name="tag_03_790"></a><!-- truncate -->
|
|
<!--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_790_01"></a>NAME</h4>
|
|
|
|
<blockquote>truncate - truncate a file to a specified length</blockquote>
|
|
|
|
<h4><a name="tag_03_790_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> #include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br>
|
|
<br>
|
|
int truncate(const char *</tt><i>path</i><tt>, off_t</tt> <i>length</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]"
|
|
border="0"></tt></code></div>
|
|
|
|
<tt><br>
|
|
</tt></blockquote>
|
|
|
|
<h4><a name="tag_03_790_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>truncate</i>() function shall cause the regular file named by <i>path</i> to have a size which shall be equal to
|
|
<i>length</i> bytes.</p>
|
|
|
|
<p>If the file previously was larger than <i>length</i>, the extra data is discarded. If the file was previously shorter than
|
|
<i>length</i>, its size is increased, and the extended area appears as if it were zero-filled.</p>
|
|
|
|
<p>The application shall ensure that the process has write permission for the file.</p>
|
|
|
|
<p>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 process.</p>
|
|
|
|
<p>This function shall not modify the file offset for any open file descriptions associated with the file. Upon successful
|
|
completion, if the file size is changed, this 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.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>truncate</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_790_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>truncate</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>
|
|
The <i>length</i> argument was greater than the maximum file size.</dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while reading from or writing to a file system.</dd>
|
|
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>A component of the path prefix denies search permission, or write permission is denied on the file.</dd>
|
|
|
|
<dt>[EISDIR]</dt>
|
|
|
|
<dd>The named file is a directory.</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 of <i>path</i> is not a directory.</dd>
|
|
|
|
<dt>[EROFS]</dt>
|
|
|
|
<dd>The named file resides on a read-only file system.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>truncate</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>
|
|
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_790_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="open.html"><i>open</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_790_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 4, Version 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_790_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_790_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>This reference page is split out from the <a href="../functions/ftruncate.html"><i>ftruncate</i>()</a> reference page.</p>
|
|
|
|
<p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p>
|
|
|
|
<p>The wording of the mandatory [ELOOP] error condition is updated, and a second optional [ELOOP] error condition is added.</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>
|
|
|