1 .\" $NetBSD: truncate.2,v 1.26 2010/05/31 12:16:20 njoly Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)truncate.2 8.1 (Berkeley) 6/4/93
38 .Nd truncate a file to a specified length
44 .Fn truncate "const char *path" "off_t length"
46 .Fn ftruncate "int fd" "off_t length"
49 causes the file named by
56 If the file previously was larger than this size, the extra data is discarded.
57 If it was previously shorter than
59 its size is increased to the specified value and
60 the extended area appears as if it were zero-filled.
64 the file must be open for writing; for
66 the process must have write permissions for the file.
68 A value of 0 is returned if the call succeeds.
69 If the call fails a \-1 is returned, and the global variable
73 Error return codes common to
80 The named file is a directory.
82 The named file resides on a read-only file system.
84 The file is a pure procedure (shared text) file that is being executed.
86 An I/O error occurred updating the inode.
88 There was no space in the filesystem to complete the operation.
91 Error codes specific to
96 A component of the path prefix is not a directory.
97 .It Bq Er ENAMETOOLONG
98 A component of a pathname exceeded
100 characters, or an entire path name exceeded
104 The named file does not exist.
106 Search permission is denied for a component of the path prefix, or
107 the named file is not writable by the user.
109 Too many symbolic links were encountered in translating the pathname.
112 points outside the process's allocated address space.
115 Error codes specific to
122 is not a valid descriptor.
126 references a socket, not a file, or
129 is not open for writing.
136 to extend a file is an
138 extension, and is thus not portable.
139 Files can be extended in a portable way seeking (using
141 to the required size and writing a single character with
148 function calls appeared in
151 These calls should be generalized to allow ranges
152 of bytes in a file to be discarded.