Changed 'caddr_t' to 'char *' -- 'caddr_t' isn't supposed to be visible
[unix-history] / usr / src / lib / libc / sys / truncate.2
CommitLineData
813c5fba
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
e52ac294 5.\" @(#)truncate.2 6.5 (Berkeley) %G%
813c5fba 6.\"
19d481fa 7.TH TRUNCATE 2 ""
813c5fba
KM
8.UC 5
9.SH NAME
10truncate \- truncate a file to a specified length
11.SH SYNOPSIS
12.nf
13.ft B
14truncate(path, length)
15char *path;
e52ac294 16off_t length;
813c5fba
KM
17.PP
18.ft B
19ftruncate(fd, length)
e52ac294
KM
20int fd;
21off_t length;
813c5fba
KM
22.fi
23.SH DESCRIPTION
24.I Truncate
25causes the file named by
26.I path
27or referenced by
28.I fd
29to be truncated to at most
30.I length
31bytes in size. If the file previously
32was larger than this size, the extra data
33is lost.
34With
35.IR ftruncate ,
36the file must be open for writing.
37.SH "RETURN VALUES
38A value of 0 is returned if the call succeeds. If the call
39fails a \-1 is returned, and the global variable \fIerrno\fP
40specifies the error.
41.SH "ERRORS
42.I Truncate
43succeeds unless:
44.TP 15
b5984ffe
KM
45[ENOTDIR]
46A component of the path prefix is not a directory.
813c5fba 47.TP 15
b5984ffe
KM
48[EINVAL]
49The pathname contains a character with the high-order bit set.
813c5fba 50.TP 15
b5984ffe
KM
51[ENAMETOOLONG]
52A component of a pathname exceeded 255 characters,
53or an entire path name exceeded 1023 characters.
813c5fba
KM
54.TP 15
55[ENOENT]
56The named file does not exist.
57.TP 15
58[EACCES]
b5984ffe
KM
59Search permission is denied for a component of the path prefix.
60.TP 15
61[ELOOP]
62Too many symbolic links were encountered in translating the pathname.
813c5fba
KM
63.TP 15
64[EISDIR]
65The named file is a directory.
66.TP 15
67[EROFS]
68The named file resides on a read-only file system.
69.TP 15
70[ETXTBSY]
71The file is a pure procedure (shared text) file that is being executed.
72.TP 15
b5984ffe
KM
73[EIO]
74An I/O error occurred updating the inode.
75.TP 15
813c5fba 76[EFAULT]
fd690c8b 77.I Path
813c5fba
KM
78points outside the process's allocated address space.
79.PP
80.I Ftruncate
81succeeds unless:
82.TP 15
83[EBADF]
84The
85.I fd
86is not a valid descriptor.
87.TP 15
88[EINVAL]
89The
90.I fd
91references a socket, not a file.
92.SH "SEE ALSO"
93open(2)
94.SH BUGS
95Partial blocks discarded as the result of truncation
96are not zero filled; this can result in holes in files
eff6446c 97that do not read as zero.
813c5fba
KM
98.PP
99These calls should be generalized to allow ranges
100of bytes in a file to be discarded.