socket/socketpair: Add SOCK_{NONBLOCK,CLOEXEC} support.
[dragonfly.git] / lib / libc / 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. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)truncate.2  8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD: src/lib/libc/sys/truncate.2,v 1.7.2.6 2001/12/14 18:34:02 ru Exp $
30 .\" $DragonFly: src/lib/libc/sys/truncate.2,v 1.3 2006/02/17 19:35:06 swildner Exp $
31 .\"
32 .Dd June 4, 1993
33 .Dt TRUNCATE 2
34 .Os
35 .Sh NAME
36 .Nm truncate ,
37 .Nm ftruncate
38 .Nd truncate or extend a file to a specified length
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In unistd.h
43 .Ft int
44 .Fn truncate "const char *path" "off_t length"
45 .Ft int
46 .Fn ftruncate "int fd" "off_t length"
47 .Sh DESCRIPTION
48 .Fn Truncate
49 causes the file named by
50 .Fa path
51 or referenced by
52 .Fa fd
53 to be truncated or extended to
54 .Fa length
55 bytes in size.  If the file
56 was larger than this size, the extra data
57 is lost.
58 If the file was smaller than this size,
59 it will be extended as if by writing bytes
60 with the value zero.
61 With
62 .Fn ftruncate ,
63 the file must be open for writing.
64 .Sh RETURN VALUES
65 .Rv -std
66 .Sh ERRORS
67 .Fn Truncate
68 succeeds unless:
69 .Bl -tag -width Er
70 .It Bq Er ENOTDIR
71 A component of the path prefix is not a directory.
72 .It Bq Er ENAMETOOLONG
73 A component of a pathname exceeded 255 characters,
74 or an entire path name exceeded 1023 characters.
75 .It Bq Er ENOENT
76 The named file does not exist.
77 .It Bq Er EACCES
78 Search permission is denied for a component of the path prefix.
79 .It Bq Er EACCES
80 The named file is not writable by the user.
81 .It Bq Er ELOOP
82 Too many symbolic links were encountered in translating the pathname.
83 .It Bq Er EISDIR
84 The named file is a directory.
85 .It Bq Er EROFS
86 The named file resides on a read-only file system.
87 .It Bq Er ETXTBSY
88 The file is a pure procedure (shared text) file that is being executed.
89 .It Bq Er EIO
90 An I/O error occurred updating the inode.
91 .It Bq Er EFAULT
92 .Fa Path
93 points outside the process's allocated address space.
94 .El
95 .Pp
96 .Fn Ftruncate
97 succeeds unless:
98 .Bl -tag -width Er
99 .It Bq Er EBADF
100 The
101 .Fa fd
102 is not a valid descriptor.
103 .It Bq Er EINVAL
104 The
105 .Fa fd
106 references a socket, not a file.
107 .It Bq Er EINVAL
108 The
109 .Fa fd
110 is not open for writing.
111 .El
112 .Sh SEE ALSO
113 .Xr open 2
114 .Sh HISTORY
115 The
116 .Fn truncate
117 function call appeared in
118 .Bx 4.2 .
119 .Sh BUGS
120 These calls should be generalized to allow ranges
121 of bytes in a file to be discarded.
122 .Pp
123 Use of
124 .Fn truncate
125 to extend a file is not portable.