1FTRUNCATE(3P)              POSIX Programmer's Manual             FTRUNCATE(3P)
2
3
4

PROLOG

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

NAME

12       ftruncate — truncate a file to a specified length
13

SYNOPSIS

15       #include <unistd.h>
16
17       int ftruncate(int fildes, off_t length);
18

DESCRIPTION

20       If fildes is not a valid file descriptor open for writing,  the  ftrun‐
21       cate() function shall fail.
22
23       If  fildes  refers  to  a  regular file, the ftruncate() function shall
24       cause the size of the file to be truncated to length.  If the  size  of
25       the  file previously exceeded length, the extra data shall no longer be
26       available to reads on the file. If the file previously was smaller than
27       this size, ftruncate() shall increase the size of the file. If the file
28       size is increased, the extended area shall appear as if it  were  zero-
29       filled.  The  value of the seek pointer shall not be modified by a call
30       to ftruncate().
31
32       Upon successful completion, if fildes refers to a regular file,  ftrun‐
33       cate()  shall  mark for update the last data modification and last file
34       status change timestamps of the file and the S_ISUID and  S_ISGID  bits
35       of  the file mode may be cleared. If the ftruncate() function is unsuc‐
36       cessful, the file is unaffected.
37
38       If the request would cause the file size to exceed the soft  file  size
39       limit  for  the  process, the request shall fail and the implementation
40       shall generate the SIGXFSZ signal for the thread.
41
42       If fildes refers to a directory, ftruncate() shall fail.
43
44       If fildes refers to any other file type, except a shared memory object,
45       the result is unspecified.
46
47       If  fildes  refers to a shared memory object, ftruncate() shall set the
48       size of the shared memory object to length.
49
50       If the effect of ftruncate() is to decrease the size of a memory mapped
51       file  or a shared memory object and whole pages beyond the new end were
52       previously mapped, then the whole pages beyond the  new  end  shall  be
53       discarded.
54
55       References  to discarded pages shall result in the generation of a SIG‐
56       BUS signal.
57
58       If the effect of ftruncate() is  to  increase  the  size  of  a  memory
59       object,  it  is  unspecified  whether  the contents of any mapped pages
60       between the old end-of-file and the new are flushed to  the  underlying
61       object.
62

RETURN VALUE

64       Upon  successful  completion, ftruncate() shall return 0; otherwise, -1
65       shall be returned and errno set to indicate the error.
66

ERRORS

68       The ftruncate() function shall fail if:
69
70       EINTR  A signal was caught during execution.
71
72       EINVAL The length argument was less than 0.
73
74       EFBIG or EINVAL
75              The length argument was greater than the maximum file size.
76
77       EFBIG  The file is a regular file and length is greater than the offset
78              maximum established in the open file description associated with
79              fildes.
80
81       EIO    An I/O error occurred while reading from or writing  to  a  file
82              system.
83
84       EBADF or EINVAL
85              The fildes argument is not a file descriptor open for writing.
86
87       The following sections are informative.
88

EXAMPLES

90       None.
91

APPLICATION USAGE

93       None.
94

RATIONALE

96       None.
97

FUTURE DIRECTIONS

99       None.
100

SEE ALSO

102       open(), truncate()
103
104       The Base Definitions volume of POSIX.1‐2017, <unistd.h>
105
107       Portions  of  this text are reprinted and reproduced in electronic form
108       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
109       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
110       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
111       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
112       event of any discrepancy between this version and the original IEEE and
113       The  Open Group Standard, the original IEEE and The Open Group Standard
114       is the referee document. The original Standard can be  obtained  online
115       at http://www.opengroup.org/unix/online.html .
116
117       Any  typographical  or  formatting  errors that appear in this page are
118       most likely to have been introduced during the conversion of the source
119       files  to  man page format. To report such errors, see https://www.ker
120       nel.org/doc/man-pages/reporting_bugs.html .
121
122
123
124IEEE/The Open Group                  2017                        FTRUNCATE(3P)
Impressum