1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)truncate.2 6.9 (Berkeley) 3/10/91
34 .\" Modified Sat Jul 24 12:46:33 1993 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified Tue Oct 22 22:36:33 1996 by Eric S. Raymond <esr@thyrsus.com>
36 .\" Modified Mon Dec 21 13:37:05 1998 by Andries Brouwer <aeb@cwi.nl>
37 .\" Modified 7 Jan 2002, Michael Kerrisk <mtk16@ext.canterbury.ac.nz>
39 .TH TRUNCATE 2 1998-12-21 "" "Linux Programmer's Manual"
41 truncate, ftruncate \- truncate a file to a specified length
43 .B #include <unistd.h>
45 .BI "int truncate(const char *" path ", off_t " length );
47 .BI "int ftruncate(int " fd ", off_t " length );
53 functions cause the regular file named by
57 to be truncated to a size of precisely
61 If the file previously was larger than this size, the extra data is lost.
62 If the file previously was shorter, it is extended, and
63 the extended part reads as zero bytes.
65 The file pointer is not changed.
69 the file must be open for writing; with
71 the file must be writable.
73 On success, zero is returned. On error, \-1 is returned, and
81 Search permission is denied for a component of the path prefix,
82 or the named file is not writable by the user.
86 points outside the process's allocated address space.
91 is larger than the maximum file size. (XSI)
94 A signal was caught during execution.
99 is negative or larger than the maximum file size.
102 An I/O error occurred updating the inode.
105 The named file is a directory.
108 Too many symbolic links were encountered in translating the pathname.
111 A component of a pathname exceeded 255 characters,
112 or an entire path name exceeded 1023 characters.
115 The named file does not exist.
118 A component of the path prefix is not a directory.
121 The named file resides on a read-only file system.
124 The file is a pure procedure (shared text) file that is being executed.
128 the same errors apply, but instead of things that can be wrong with
130 we now have things that can be wrong with
136 is not a valid descriptor.
138 .BR EBADF " or " EINVAL
141 is not open for writing.
146 does not reference a regular file.
148 4.4BSD, SVr4 (these function calls first appeared in BSD 4.2).
149 POSIX 1003.1-1996 has
151 POSIX 1003.1-2001 also has
155 SVr4 documents additional
157 error conditions EMFILE, EMULTIHP, ENFILE, ENOLINK. SVr4 documents for
159 an additional EAGAIN error condition.
161 The above description is for XSI-compliant systems.
162 For non-XSI-compliant systems, the POSIX standard allows
167 exceeds the file length
170 is not specified at all in such an environment):
171 either returning an error, or extending the file.
172 (Most Unices follow the XSI requirement.)
173 .\" At the very least: OSF/1, Solaris 7, and FreeBSD conform, mtk, Jan 2002