]> git.pld-linux.org Git - packages/man-pages.git/blame - truncate.2
- separated POSIX man pages, rel. 1
[packages/man-pages.git] / truncate.2
CommitLineData
24b7bc57 1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
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.
19.\"
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
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)truncate.2 6.9 (Berkeley) 3/10/91
33.\"
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>
38.\"
39.TH TRUNCATE 2 1998-12-21 "" "Linux Programmer's Manual"
40.SH NAME
41truncate, ftruncate \- truncate a file to a specified length
42.SH SYNOPSIS
43.B #include <unistd.h>
44.sp
45.BI "int truncate(const char *" path ", off_t " length );
46.br
47.BI "int ftruncate(int " fd ", off_t " length );
48.SH DESCRIPTION
49The
50.B truncate
51and
52.B ftruncate
53functions cause the regular file named by
54.I path
55or referenced by
56.I fd
57to be truncated to a size of precisely
58.I length
59bytes.
60.LP
61If the file previously was larger than this size, the extra data is lost.
62If the file previously was shorter, it is extended, and
63the extended part reads as zero bytes.
64.LP
65The file pointer is not changed.
66.LP
67With
68.BR ftruncate ,
69the file must be open for writing; with
70.BR truncate ,
71the file must be writable.
72.SH "RETURN VALUE"
73On success, zero is returned. On error, \-1 is returned, and
74.I errno
75is set appropriately.
76.SH ERRORS
77For
78.BR truncate :
79.TP
80.B EACCES
81Search permission is denied for a component of the path prefix,
82or the named file is not writable by the user.
83.TP
84.B EFAULT
85.I Path
86points outside the process's allocated address space.
87.TP
88.B EFBIG
89The argument
90.I length
91is larger than the maximum file size. (XSI)
92.TP
93.B EINTR
94A signal was caught during execution.
95.TP
96.B EINVAL
97The argument
98.I length
99is negative or larger than the maximum file size.
100.TP
101.B EIO
102An I/O error occurred updating the inode.
103.TP
104.B EISDIR
105The named file is a directory.
106.TP
107.B ELOOP
108Too many symbolic links were encountered in translating the pathname.
109.TP
110.B ENAMETOOLONG
111A component of a pathname exceeded 255 characters,
112or an entire path name exceeded 1023 characters.
113.TP
114.B ENOENT
115The named file does not exist.
116.TP
117.B ENOTDIR
118A component of the path prefix is not a directory.
119.TP
120.B EROFS
121The named file resides on a read-only file system.
122.TP
123.B ETXTBSY
124The file is a pure procedure (shared text) file that is being executed.
125.PP
126For
127.B ftruncate
128the same errors apply, but instead of things that can be wrong with
129.IR path ,
130we now have things that can be wrong with
131.IR fd :
132.TP
133.B EBADF
134The
135.I fd
136is not a valid descriptor.
137.TP
138.BR EBADF " or " EINVAL
139The
140.I fd
141is not open for writing.
142.TP
143.B EINVAL
144The
145.I fd
146does not reference a regular file.
147.SH "CONFORMING TO"
1484.4BSD, SVr4 (these function calls first appeared in BSD 4.2).
149POSIX 1003.1-1996 has
150.BR ftruncate .
151POSIX 1003.1-2001 also has
152.IR truncate ,
153as an XSI extension.
154.LP
155SVr4 documents additional
156.B truncate
157error conditions EMFILE, EMULTIHP, ENFILE, ENOLINK. SVr4 documents for
158.B ftruncate
159an additional EAGAIN error condition.
160.SH NOTES
161The above description is for XSI-compliant systems.
162For non-XSI-compliant systems, the POSIX standard allows
163two behaviours for
164.B ftruncate
165when
166.I length
167exceeds the file length
168(note that
169.B truncate
170is not specified at all in such an environment):
171either 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
174.SH "SEE ALSO"
175.BR open (2)
This page took 0.046373 seconds and 4 git commands to generate.