1FTRUNCATE(3P) POSIX Programmer's Manual FTRUNCATE(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 ftruncate — truncate a file to a specified length
14
16 #include <unistd.h>
17
18 int ftruncate(int fildes, off_t length);
19
21 If fildes is not a valid file descriptor open for writing, the ftrun‐
22 cate() function shall fail.
23
24 If fildes refers to a regular file, the ftruncate() function shall
25 cause the size of the file to be truncated to length. If the size of
26 the file previously exceeded length, the extra data shall no longer be
27 available to reads on the file. If the file previously was smaller than
28 this size, ftruncate() shall increase the size of the file. If the file
29 size is increased, the extended area shall appear as if it were zero-
30 filled. The value of the seek pointer shall not be modified by a call
31 to ftruncate().
32
33 Upon successful completion, if fildes refers to a regular file, ftrun‐
34 cate() shall mark for update the last data modification and last file
35 status change timestamps of the file and the S_ISUID and S_ISGID bits
36 of the file mode may be cleared. If the ftruncate() function is unsuc‐
37 cessful, the file is unaffected.
38
39 If the request would cause the file size to exceed the soft file size
40 limit for the process, the request shall fail and the implementation
41 shall generate the SIGXFSZ signal for the thread.
42
43 If fildes refers to a directory, ftruncate() shall fail.
44
45 If fildes refers to any other file type, except a shared memory object,
46 the result is unspecified.
47
48 If fildes refers to a shared memory object, ftruncate() shall set the
49 size of the shared memory object to length.
50
51 If the effect of ftruncate() is to decrease the size of a memory mapped
52 file or a shared memory object and whole pages beyond the new end were
53 previously mapped, then the whole pages beyond the new end shall be
54 discarded.
55
56 References to discarded pages shall result in the generation of a SIG‐
57 BUS signal.
58
59 If the effect of ftruncate() is to increase the size of a memory
60 object, it is unspecified whether the contents of any mapped pages
61 between the old end-of-file and the new are flushed to the underlying
62 object.
63
65 Upon successful completion, ftruncate() shall return 0; otherwise, −1
66 shall be returned and errno set to indicate the error.
67
69 The ftruncate() function shall fail if:
70
71 EINTR A signal was caught during execution.
72
73 EINVAL The length argument was less than 0.
74
75 EFBIG or EINVAL
76 The length argument was greater than the maximum file size.
77
78 EFBIG The file is a regular file and length is greater than the offset
79 maximum established in the open file description associated with
80 fildes.
81
82 EIO An I/O error occurred while reading from or writing to a file
83 system.
84
85 EBADF or EINVAL
86 The fildes argument is not a file descriptor open for writing.
87
88 The following sections are informative.
89
91 None.
92
94 None.
95
97 None.
98
100 None.
101
103 open(), truncate()
104
105 The Base Definitions volume of POSIX.1‐2008, <unistd.h>
106
108 Portions of this text are reprinted and reproduced in electronic form
109 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
110 -- Portable Operating System Interface (POSIX), The Open Group Base
111 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
112 cal and Electronics Engineers, Inc and The Open Group. (This is
113 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
114 event of any discrepancy between this version and the original IEEE and
115 The Open Group Standard, the original IEEE and The Open Group Standard
116 is the referee document. The original Standard can be obtained online
117 at http://www.unix.org/online.html .
118
119 Any typographical or formatting errors that appear in this page are
120 most likely to have been introduced during the conversion of the source
121 files to man page format. To report such errors, see https://www.ker‐
122 nel.org/doc/man-pages/reporting_bugs.html .
123
124
125
126IEEE/The Open Group 2013 FTRUNCATE(3P)