add note about finding the end of memory
[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.\"
234f27d4 5.\" @(#)truncate.2 6.6 (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
234f27d4
JL
61[EACCES]
62The named file is not writable by the user.
63.TP 15
b5984ffe
KM
64[ELOOP]
65Too many symbolic links were encountered in translating the pathname.
813c5fba
KM
66.TP 15
67[EISDIR]
68The named file is a directory.
69.TP 15
70[EROFS]
71The named file resides on a read-only file system.
72.TP 15
73[ETXTBSY]
74The file is a pure procedure (shared text) file that is being executed.
75.TP 15
b5984ffe
KM
76[EIO]
77An I/O error occurred updating the inode.
78.TP 15
813c5fba 79[EFAULT]
fd690c8b 80.I Path
813c5fba
KM
81points outside the process's allocated address space.
82.PP
83.I Ftruncate
84succeeds unless:
85.TP 15
86[EBADF]
87The
88.I fd
89is not a valid descriptor.
90.TP 15
91[EINVAL]
92The
93.I fd
94references a socket, not a file.
234f27d4
JL
95.TP 15
96[EINVAL]
97The
98.I fd
99is not open for writing.
813c5fba
KM
100.SH "SEE ALSO"
101open(2)
102.SH BUGS
813c5fba
KM
103These calls should be generalized to allow ranges
104of bytes in a file to be discarded.