2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
47 .TH TRUNCATE 3C "Apr 5, 2002"
49 truncate, ftruncate \- set a file to a specified length
55 \fBint\fR \fBtruncate\fR(\fBconst char *\fR\fIpath\fR, \fBoff_t\fR \fIlength\fR);
60 \fBint\fR \fBftruncate\fR(\fBint\fR \fIfildes\fR, \fBoff_t\fR \fIlength\fR);
66 The \fBtruncate()\fR function causes the regular file named by \fIpath\fR to
67 have a size equal to \fIlength\fR bytes.
70 If the file previously was larger than \fIlength\fR, the extra data is
71 discarded. If the file was previously shorter than length, its size is
72 increased, and the extended area appears as if it were zero-filled.
75 The application must ensure that the process has write permission for the file.
78 This function does not modify the file offset for any open file descriptions
79 associated with the file.
82 The \fBftruncate()\fR function causes the regular file referenced by
83 \fIfildes\fR to be truncated to \fIlength\fR. If the size of the file
84 previously exceeded \fIlength\fR, the extra data is no longer available to
85 reads on the file. If the file previously was smaller than this size,
86 \fBftruncate()\fR increases the size of the file with the extended area
87 appearing as if it were zero-filled. The value of the seek pointer is not
88 modified by a call to \fBftruncate()\fR.
91 The \fBftruncate()\fR function works only with regular files and shared memory.
92 If \fIfildes\fR refers to a shared memory object, \fBftruncate()\fR sets the
93 size of the shared memory object to \fIlength\fR. If \fIfildes\fR refers to a
94 directory or is not a valid file descriptor open for writing, \fBftruncate()\fR
98 If the effect of \fBftruncate()\fR is to decrease the size of a shared memory
99 object or memory mapped file and whole pages beyond the new end were previously
100 mapped, then the whole pages beyond the new end shall be discarded.
103 If the effect of \fBftruncate()\fR is to increase the size of a shared memory
104 object, it is unspecified if the contents of any mapped pages between the old
105 end-of-file and the new are flushed to the underlying object.
108 These functions do not modify the file offset for any open file descriptions
109 associated with the file. On successful completion, if the file size is
110 changed, these functions will mark for update the \fBst_ctime\fR and
111 \fBst_mtime\fR fields of the file, and if the file is a regular file, the
112 \fBS_ISUID\fR and \fBS_ISGID\fR bits of the file mode are left unchanged.
115 If the request would cause the file size to exceed the soft file size limit for
116 the process, the request will fail and a \fBSIGXFSZ\fR signal will be generated
121 Upon successful completion, \fBftruncate()\fR and \fBtruncate()\fR return
122 \fB0\fR. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate
127 The \fBftruncate()\fR and \fBtruncate()\fR functions will fail if:
134 A signal was caught during execution.
143 The \fIlength\fR argument was less than 0.
149 \fB\fBEFBIG\fR or \fBEINVAL\fR\fR
152 The \fIlength\fR argument was greater than the maximum file size.
161 An I/O error occurred while reading from or writing to a file system.
170 The named file resides on a read-only file system.
175 The \fBtruncate()\fR function will fail if:
182 A component of the path prefix denies search permission, or write permission is
192 The \fIpath\fR argument points outside the process' allocated address space.
201 The \fIpath\fR argument is not an ordinary file.
210 The named file is a directory.
219 Too many symbolic links were encountered in resolving \fIpath\fR.
228 The maximum number of file descriptors available to the process has been
235 \fB\fBENAMETOOLONG\fR\fR
238 The length of the specified pathname exceeds {\fBPATH_MAX\fR} bytes, or the
239 length of a component of the pathname exceeds {\fBNAME_MAX\fR} bytes.
248 A component of \fIpath\fR does not name an existing file or \fIpath\fR is an
258 Additional space could not be allocated for the system file table.
267 A component of the path prefix of \fIpath\fR is not a directory.
276 The \fIpath\fR argument points to a remote machine and the link to that machine
282 The \fBftruncate()\fR function will fail if:
289 The file exists, mandatory file/record locking is set, and there are
290 outstanding record locks on the file (see \fBchmod\fR(2)).
296 \fB\fBEBADF\fR or \fBEINVAL\fR\fR
299 The \fIfildes\fR argument is not a file descriptor open for writing.
308 The file is a regular file and \fIlength\fR is greater than the offset maximum
309 established in the open file description associated with \fIfildes\fR.
318 The \fIfildes\fR argument references a file that was opened without write
328 The \fIfildes\fR argument does not correspond to an ordinary file.
337 The \fIfildes\fR argument points to a remote machine and the link to that
338 machine is no longer active.
343 The \fBtruncate()\fR function may fail if:
347 \fB\fBENAMETOOLONG\fR\fR
350 Pathname resolution of a symbolic link produced an intermediate result whose
351 length exceeds {\fBPATH_MAX\fR}.
357 See \fBattributes\fR(5) for descriptions of the following attributes:
365 ATTRIBUTE TYPE ATTRIBUTE VALUE
367 Interface Stability Standard
375 \fBchmod\fR(2), \fBfcntl\fR(2), \fBopen\fR(2), \fBattributes\fR(5),