FTRUNCATE(3)               POSIX Programmer's Manual              FTRUNCATE(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       ftruncate -- truncate a file to a specified length

SSYYNNOOPPSSIISS
       #include <unistd.h>

       int ftruncate(int _f_i_l_d_e_s, off_t _l_e_n_g_t_h);

DDEESSCCRRIIPPTTIIOONN
       If _f_i_l_d_e_s is not a valid file descriptor open for writing, the
       _f_t_r_u_n_c_a_t_e() function shall fail.

       If _f_i_l_d_e_s refers to a regular file, the _f_t_r_u_n_c_a_t_e() function shall
       cause the size of the file to be truncated to _l_e_n_g_t_h.  If the size of
       the file previously exceeded _l_e_n_g_t_h, the extra data shall no longer be
       available to reads on the file. If the file previously was smaller than
       this size, _f_t_r_u_n_c_a_t_e() shall increase the size of the file. If the file
       size is increased, the extended area shall appear as if it were zero-
       filled. The value of the seek pointer shall not be modified by a call
       to _f_t_r_u_n_c_a_t_e().

       Upon successful completion, if _f_i_l_d_e_s refers to a regular file,
       _f_t_r_u_n_c_a_t_e() shall mark for update the last data modification and last
       file status change timestamps of the file and the S_ISUID and S_ISGID
       bits of the file mode may be cleared. If the _f_t_r_u_n_c_a_t_e() function is
       unsuccessful, the file is unaffected.

       If the request would cause the file size to exceed the soft file size
       limit for the process, the request shall fail and the implementation
       shall generate the SIGXFSZ signal for the thread.

       If _f_i_l_d_e_s refers to a directory, _f_t_r_u_n_c_a_t_e() shall fail.

       If _f_i_l_d_e_s refers to any other file type, except a shared memory object,
       the result is unspecified.

       If _f_i_l_d_e_s refers to a shared memory object, _f_t_r_u_n_c_a_t_e() shall set the
       size of the shared memory object to _l_e_n_g_t_h.

       If the effect of _f_t_r_u_n_c_a_t_e() is to decrease the size of a memory mapped
       file or a shared memory object and whole pages beyond the new end were
       previously mapped, then the whole pages beyond the new end shall be
       discarded.

       References to discarded pages shall result in the generation of a
       SIGBUS signal.

       If the effect of _f_t_r_u_n_c_a_t_e() is to increase the size of a memory
       object, it is unspecified whether the contents of any mapped pages
       between the old end-of-file and the new are flushed to the underlying
       object.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _f_t_r_u_n_c_a_t_e() shall return 0; otherwise, -1
       shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _f_t_r_u_n_c_a_t_e() function shall fail if:

       EEIINNTTRR  A signal was caught during execution.

       EEIINNVVAALL The _l_e_n_g_t_h argument was less than 0.

       EEFFBBIIGG or EEIINNVVAALL
              The _l_e_n_g_t_h argument was greater than the maximum file size.

       EEFFBBIIGG  The file is a regular file and _l_e_n_g_t_h is greater than the offset
              maximum established in the open file description associated with
              _f_i_l_d_e_s.

       EEIIOO    An I/O error occurred while reading from or writing to a file
              system.

       EEBBAADDFF or EEIINNVVAALL
              The _f_i_l_d_e_s argument is not a file descriptor open for writing.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _o_p_e_n(), _t_r_u_n_c_a_t_e()

       The Base Definitions volume of POSIX.1-2008, <<uunniissttdd..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                         FTRUNCATE(3)
