Commit | Line | Data |
---|---|---|
15715acc KB |
1 | .\" Copyright (c) 1983, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
813c5fba | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
88b3ccf2 | 5 | .\" |
15715acc | 6 | .\" @(#)truncate.2 8.1 (Berkeley) %G% |
813c5fba | 7 | .\" |
931b8415 CL |
8 | .Dd |
9 | .Dt TRUNCATE 2 | |
10 | .Os BSD 4.2 | |
11 | .Sh NAME | |
12 | .Nm truncate , | |
13 | .Nm ftruncate | |
14 | .Nd truncate a file to a specified length | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <unistd.h> | |
17 | .Ft int | |
18 | .Fn truncate "const char *path" "off_t length" | |
19 | .Ft int | |
20 | .Fn ftruncate "int fd" "off_t length" | |
21 | .Sh DESCRIPTION | |
22 | .Fn Truncate | |
813c5fba | 23 | causes the file named by |
931b8415 | 24 | .Fa path |
813c5fba | 25 | or referenced by |
931b8415 | 26 | .Fa fd |
813c5fba | 27 | to be truncated to at most |
931b8415 | 28 | .Fa length |
813c5fba KM |
29 | bytes in size. If the file previously |
30 | was larger than this size, the extra data | |
31 | is lost. | |
32 | With | |
931b8415 | 33 | .Fn ftruncate , |
813c5fba | 34 | the file must be open for writing. |
931b8415 | 35 | .Sh RETURN VALUES |
813c5fba | 36 | A value of 0 is returned if the call succeeds. If the call |
931b8415 CL |
37 | fails a -1 is returned, and the global variable |
38 | .Va errno | |
813c5fba | 39 | specifies the error. |
931b8415 CL |
40 | .Sh ERRORS |
41 | .Fn Truncate | |
813c5fba | 42 | succeeds unless: |
931b8415 CL |
43 | .Bl -tag -width [ENOTDIR] |
44 | .It Bq Er ENOTDIR | |
b5984ffe | 45 | A component of the path prefix is not a directory. |
931b8415 | 46 | .It Bq Er EINVAL |
b5984ffe | 47 | The pathname contains a character with the high-order bit set. |
931b8415 | 48 | .It Bq Er ENAMETOOLONG |
b5984ffe KM |
49 | A component of a pathname exceeded 255 characters, |
50 | or an entire path name exceeded 1023 characters. | |
931b8415 | 51 | .It Bq Er ENOENT |
813c5fba | 52 | The named file does not exist. |
931b8415 | 53 | .It Bq Er EACCES |
b5984ffe | 54 | Search permission is denied for a component of the path prefix. |
931b8415 | 55 | .It Bq Er EACCES |
234f27d4 | 56 | The named file is not writable by the user. |
931b8415 | 57 | .It Bq Er ELOOP |
b5984ffe | 58 | Too many symbolic links were encountered in translating the pathname. |
931b8415 | 59 | .It Bq Er EISDIR |
813c5fba | 60 | The named file is a directory. |
931b8415 | 61 | .It Bq Er EROFS |
813c5fba | 62 | The named file resides on a read-only file system. |
931b8415 | 63 | .It Bq Er ETXTBSY |
813c5fba | 64 | The file is a pure procedure (shared text) file that is being executed. |
931b8415 | 65 | .It Bq Er EIO |
b5984ffe | 66 | An I/O error occurred updating the inode. |
931b8415 CL |
67 | .It Bq Er EFAULT |
68 | .Fa Path | |
813c5fba | 69 | points outside the process's allocated address space. |
931b8415 CL |
70 | .El |
71 | .Pp | |
72 | .Fn Ftruncate | |
813c5fba | 73 | succeeds unless: |
931b8415 CL |
74 | .Bl -tag -width [ENOTDIR] |
75 | .It Bq Er EBADF | |
813c5fba | 76 | The |
931b8415 | 77 | .Fa fd |
813c5fba | 78 | is not a valid descriptor. |
931b8415 | 79 | .It Bq Er EINVAL |
813c5fba | 80 | The |
931b8415 | 81 | .Fa fd |
813c5fba | 82 | references a socket, not a file. |
931b8415 | 83 | .It Bq Er EINVAL |
234f27d4 | 84 | The |
931b8415 | 85 | .Fa fd |
234f27d4 | 86 | is not open for writing. |
931b8415 CL |
87 | .El |
88 | .Sh SEE ALSO | |
89 | .Xr open 2 | |
90 | .Sh BUGS | |
813c5fba KM |
91 | These calls should be generalized to allow ranges |
92 | of bytes in a file to be discarded. | |
931b8415 CL |
93 | .Sh HISTORY |
94 | The | |
95 | .Nm | |
96 | function call appeared in | |
97 | .Bx 4.2 . |