Section: POSIX Programmer's Manual (3P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- truncate a file to a specified length
int truncate(const char *path, off_t length);
function shall cause the regular file named by
to have a size which shall be equal to
If the file previously was larger than
the extra data is discarded. If the file was previously shorter than
its size is increased, and the extended area appears as if it were
The application shall ensure that the process has write permission for
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 process.
function shall not modify the file offset for any open file descriptions
associated with the file. Upon successful completion, if the file size
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.
Upon successful completion,
shall return 0. Otherwise, -1 shall be returned, and
set to indicate the error.
function shall fail if:
A signal was caught during execution.
argument was less than 0.
- EFBIG or EINVAL
argument was greater than the maximum file size.
An I/O error occurred while reading from or writing to a file system.
A component of the path prefix denies search permission, or write
permission is denied on the file.
The named file is a directory.
A loop exists in symbolic links encountered during resolution of the
The length of a component of a pathname is longer than
A component of
does not name an existing file or
is an empty string.
A component of the path prefix names an existing file that is neither
a directory nor a symbolic link to a directory, or the
argument contains at least one non-<slash>
character and ends with one or more trailing
characters and the last pathname component names an existing file
that is neither a directory nor a symbolic link to a directory.
The named file resides on a read-only file system.
function may fail if:
symbolic links were encountered during resolution of the
The length of a pathname exceeds
or pathname resolution of a symbolic link produced an intermediate
result with a length that exceeds
The following sections are informative.
The Base Definitions volume of POSIX.1-2008,
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
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