Initial import from FreeBSD RELENG_4:
[dragonfly.git] / lib / libcr / sys / truncate.2
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  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  8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/truncate.2,v 1.7.2.6 2001/12/14 18:34:02 ru Exp $
34 .\"
35 .Dd June 4, 1993
36 .Dt TRUNCATE 2
37 .Os
38 .Sh NAME
39 .Nm truncate ,
40 .Nm ftruncate
41 .Nd truncate or extend a file to a specified length
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In unistd.h
46 .Ft int
47 .Fn truncate "const char *path" "off_t length"
48 .Ft int
49 .Fn ftruncate "int fd" "off_t length"
50 .Sh DESCRIPTION
51 .Fn Truncate
52 causes the file named by
53 .Fa path
54 or referenced by
55 .Fa fd
56 to be truncated or extended to
57 .Fa length
58 bytes in size.  If the file
59 was larger than this size, the extra data
60 is lost.
61 If the file was smaller than this size,
62 it will be extended as if by writing bytes
63 with the value zero.
64 With
65 .Fn ftruncate ,
66 the file must be open for writing.
67 .Sh RETURN VALUES
68 .Rv -std
69 .Sh ERRORS
70 .Fn Truncate
71 succeeds unless:
72 .Bl -tag -width Er
73 .It Bq Er ENOTDIR
74 A component of the path prefix is not a directory.
75 .It Bq Er ENAMETOOLONG
76 A component of a pathname exceeded 255 characters,
77 or an entire path name exceeded 1023 characters.
78 .It Bq Er ENOENT
79 The named file does not exist.
80 .It Bq Er EACCES
81 Search permission is denied for a component of the path prefix.
82 .It Bq Er EACCES
83 The named file is not writable by the user.
84 .It Bq Er ELOOP
85 Too many symbolic links were encountered in translating the pathname.
86 .It Bq Er EISDIR
87 The named file is a directory.
88 .It Bq Er EROFS
89 The named file resides on a read-only file system.
90 .It Bq Er ETXTBSY
91 The file is a pure procedure (shared text) file that is being executed.
92 .It Bq Er EIO
93 An I/O error occurred updating the inode.
94 .It Bq Er EFAULT
95 .Fa Path
96 points outside the process's allocated address space.
97 .El
98 .Pp
99 .Fn Ftruncate
100 succeeds unless:
101 .Bl -tag -width Er
102 .It Bq Er EBADF
103 The
104 .Fa fd
105 is not a valid descriptor.
106 .It Bq Er EINVAL
107 The
108 .Fa fd
109 references a socket, not a file.
110 .It Bq Er EINVAL
111 The
112 .Fa fd
113 is not open for writing.
114 .El
115 .Sh SEE ALSO
116 .Xr open 2
117 .Sh BUGS
118 These calls should be generalized to allow ranges
119 of bytes in a file to be discarded.
120 .Pp
121 Use of
122 .Fn truncate
123 to extend a file is not portable.
124 .Sh HISTORY
125 The
126 .Fn truncate
127 function call appeared in
128 .Bx 4.2 .