minor error inspec
[unix-history] / usr / src / lib / libc / sys / truncate.2
CommitLineData
88b3ccf2
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
813c5fba 3.\"
88b3ccf2
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)truncate.2 6.7 (Berkeley) %G%
813c5fba 17.\"
19d481fa 18.TH TRUNCATE 2 ""
813c5fba
KM
19.UC 5
20.SH NAME
21truncate \- truncate a file to a specified length
22.SH SYNOPSIS
23.nf
24.ft B
25truncate(path, length)
26char *path;
e52ac294 27off_t length;
813c5fba
KM
28.PP
29.ft B
30ftruncate(fd, length)
e52ac294
KM
31int fd;
32off_t length;
813c5fba
KM
33.fi
34.SH DESCRIPTION
35.I Truncate
36causes the file named by
37.I path
38or referenced by
39.I fd
40to be truncated to at most
41.I length
42bytes in size. If the file previously
43was larger than this size, the extra data
44is lost.
45With
46.IR ftruncate ,
47the file must be open for writing.
48.SH "RETURN VALUES
49A value of 0 is returned if the call succeeds. If the call
50fails a \-1 is returned, and the global variable \fIerrno\fP
51specifies the error.
52.SH "ERRORS
53.I Truncate
54succeeds unless:
55.TP 15
b5984ffe
KM
56[ENOTDIR]
57A component of the path prefix is not a directory.
813c5fba 58.TP 15
b5984ffe
KM
59[EINVAL]
60The pathname contains a character with the high-order bit set.
813c5fba 61.TP 15
b5984ffe
KM
62[ENAMETOOLONG]
63A component of a pathname exceeded 255 characters,
64or an entire path name exceeded 1023 characters.
813c5fba
KM
65.TP 15
66[ENOENT]
67The named file does not exist.
68.TP 15
69[EACCES]
b5984ffe
KM
70Search permission is denied for a component of the path prefix.
71.TP 15
234f27d4
JL
72[EACCES]
73The named file is not writable by the user.
74.TP 15
b5984ffe
KM
75[ELOOP]
76Too many symbolic links were encountered in translating the pathname.
813c5fba
KM
77.TP 15
78[EISDIR]
79The named file is a directory.
80.TP 15
81[EROFS]
82The named file resides on a read-only file system.
83.TP 15
84[ETXTBSY]
85The file is a pure procedure (shared text) file that is being executed.
86.TP 15
b5984ffe
KM
87[EIO]
88An I/O error occurred updating the inode.
89.TP 15
813c5fba 90[EFAULT]
fd690c8b 91.I Path
813c5fba
KM
92points outside the process's allocated address space.
93.PP
94.I Ftruncate
95succeeds unless:
96.TP 15
97[EBADF]
98The
99.I fd
100is not a valid descriptor.
101.TP 15
102[EINVAL]
103The
104.I fd
105references a socket, not a file.
234f27d4
JL
106.TP 15
107[EINVAL]
108The
109.I fd
110is not open for writing.
813c5fba
KM
111.SH "SEE ALSO"
112open(2)
113.SH BUGS
813c5fba
KM
114These calls should be generalized to allow ranges
115of bytes in a file to be discarded.