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