improved english
[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.\"
eff6446c 5.\" @(#)truncate.2 6.3 (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;
16int length;
17.PP
18.ft B
19ftruncate(fd, length)
20int fd, length;
21.fi
22.SH DESCRIPTION
23.I Truncate
24causes the file named by
25.I path
26or referenced by
27.I fd
28to be truncated to at most
29.I length
30bytes in size. If the file previously
31was larger than this size, the extra data
32is lost.
33With
34.IR ftruncate ,
35the file must be open for writing.
36.SH "RETURN VALUES
37A value of 0 is returned if the call succeeds. If the call
38fails a \-1 is returned, and the global variable \fIerrno\fP
39specifies the error.
40.SH "ERRORS
41.I Truncate
42succeeds unless:
43.TP 15
b5984ffe
KM
44[ENOTDIR]
45A component of the path prefix is not a directory.
813c5fba 46.TP 15
b5984ffe
KM
47[EINVAL]
48The pathname contains a character with the high-order bit set.
813c5fba 49.TP 15
b5984ffe
KM
50[ENAMETOOLONG]
51A component of a pathname exceeded 255 characters,
52or an entire path name exceeded 1023 characters.
813c5fba
KM
53.TP 15
54[ENOENT]
55The named file does not exist.
56.TP 15
57[EACCES]
b5984ffe
KM
58Search permission is denied for a component of the path prefix.
59.TP 15
60[ELOOP]
61Too many symbolic links were encountered in translating the pathname.
813c5fba
KM
62.TP 15
63[EISDIR]
64The named file is a directory.
65.TP 15
66[EROFS]
67The named file resides on a read-only file system.
68.TP 15
69[ETXTBSY]
70The file is a pure procedure (shared text) file that is being executed.
71.TP 15
b5984ffe
KM
72[EIO]
73An I/O error occurred updating the inode.
74.TP 15
813c5fba
KM
75[EFAULT]
76.I Name
77points outside the process's allocated address space.
78.PP
79.I Ftruncate
80succeeds unless:
81.TP 15
82[EBADF]
83The
84.I fd
85is not a valid descriptor.
86.TP 15
87[EINVAL]
88The
89.I fd
90references a socket, not a file.
91.SH "SEE ALSO"
92open(2)
93.SH BUGS
94Partial blocks discarded as the result of truncation
95are not zero filled; this can result in holes in files
eff6446c 96that do not read as zero.
813c5fba
KM
97.PP
98These calls should be generalized to allow ranges
99of bytes in a file to be discarded.