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