2 .\" Copyright 1989 AT&T Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\" This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH TRUNCATE 3C "Apr 5, 2002"
12 truncate, ftruncate \- set a file to a specified length
18 \fBint\fR \fBtruncate\fR(\fBconst char *\fR\fIpath\fR, \fBoff_t\fR \fIlength\fR);
23 \fBint\fR \fBftruncate\fR(\fBint\fR \fIfildes\fR, \fBoff_t\fR \fIlength\fR);
29 The \fBtruncate()\fR function causes the regular file named by \fIpath\fR to
30 have a size equal to \fIlength\fR bytes.
33 If the file previously was larger than \fIlength\fR, the extra data is
34 discarded. If the file was previously shorter than length, its size is
35 increased, and the extended area appears as if it were zero-filled.
38 The application must ensure that the process has write permission for the file.
41 This function does not modify the file offset for any open file descriptions
42 associated with the file.
45 The \fBftruncate()\fR function causes the regular file referenced by
46 \fIfildes\fR to be truncated to \fIlength\fR. If the size of the file
47 previously exceeded \fIlength\fR, the extra data is no longer available to
48 reads on the file. If the file previously was smaller than this size,
49 \fBftruncate()\fR increases the size of the file with the extended area
50 appearing as if it were zero-filled. The value of the seek pointer is not
51 modified by a call to \fBftruncate()\fR.
54 The \fBftruncate()\fR function works only with regular files and shared memory.
55 If \fIfildes\fR refers to a shared memory object, \fBftruncate()\fR sets the
56 size of the shared memory object to \fIlength\fR. If \fIfildes\fR refers to a
57 directory or is not a valid file descriptor open for writing, \fBftruncate()\fR
61 If the effect of \fBftruncate()\fR is to decrease the size of a shared memory
62 object or memory mapped file and whole pages beyond the new end were previously
63 mapped, then the whole pages beyond the new end shall be discarded.
66 If the effect of \fBftruncate()\fR is to increase the size of a shared memory
67 object, it is unspecified if the contents of any mapped pages between the old
68 end-of-file and the new are flushed to the underlying object.
71 These functions do not modify the file offset for any open file descriptions
72 associated with the file. On successful completion, if the file size is
73 changed, these functions will mark for update the \fBst_ctime\fR and
74 \fBst_mtime\fR fields of the file, and if the file is a regular file, the
75 \fBS_ISUID\fR and \fBS_ISGID\fR bits of the file mode are left unchanged.
78 If the request would cause the file size to exceed the soft file size limit for
79 the process, the request will fail and a \fBSIGXFSZ\fR signal will be generated
84 Upon successful completion, \fBftruncate()\fR and \fBtruncate()\fR return
85 \fB0\fR. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate
90 The \fBftruncate()\fR and \fBtruncate()\fR functions will fail if:
97 A signal was caught during execution.
106 The \fIlength\fR argument was less than 0.
112 \fB\fBEFBIG\fR or \fBEINVAL\fR\fR
115 The \fIlength\fR argument was greater than the maximum file size.
124 An I/O error occurred while reading from or writing to a file system.
133 The named file resides on a read-only file system.
138 The \fBtruncate()\fR function will fail if:
145 A component of the path prefix denies search permission, or write permission is
155 The \fIpath\fR argument points outside the process' allocated address space.
164 The \fIpath\fR argument is not an ordinary file.
173 The named file is a directory.
182 Too many symbolic links were encountered in resolving \fIpath\fR.
191 The maximum number of file descriptors available to the process has been
198 \fB\fBENAMETOOLONG\fR\fR
201 The length of the specified pathname exceeds {\fBPATH_MAX\fR} bytes, or the
202 length of a component of the pathname exceeds {\fBNAME_MAX\fR} bytes.
211 A component of \fIpath\fR does not name an existing file or \fIpath\fR is an
221 Additional space could not be allocated for the system file table.
230 A component of the path prefix of \fIpath\fR is not a directory.
239 The \fIpath\fR argument points to a remote machine and the link to that machine
245 The \fBftruncate()\fR function will fail if:
252 The file exists, mandatory file/record locking is set, and there are
253 outstanding record locks on the file (see \fBchmod\fR(2)).
259 \fB\fBEBADF\fR or \fBEINVAL\fR\fR
262 The \fIfildes\fR argument is not a file descriptor open for writing.
271 The file is a regular file and \fIlength\fR is greater than the offset maximum
272 established in the open file description associated with \fIfildes\fR.
281 The \fIfildes\fR argument references a file that was opened without write
291 The \fIfildes\fR argument does not correspond to an ordinary file.
300 The \fIfildes\fR argument points to a remote machine and the link to that
301 machine is no longer active.
306 The \fBtruncate()\fR function may fail if:
310 \fB\fBENAMETOOLONG\fR\fR
313 Pathname resolution of a symbolic link produced an intermediate result whose
314 length exceeds {\fBPATH_MAX\fR}.
320 The \fBtruncate()\fR and \fBftruncate()\fR functions have transitional
321 interfaces for 64-bit file offsets. See \fBlf64\fR(5).
325 See \fBattributes\fR(5) for descriptions of the following attributes:
333 ATTRIBUTE TYPE ATTRIBUTE VALUE
335 Interface Stability Standard
343 \fBchmod\fR(2), \fBfcntl\fR(2), \fBopen\fR(2), \fBattributes\fR(5),
344 \fBlf64\fR(5), \fBstandards\fR(5)