TRUNCATESection: Linux Programmer's Manual (2)
Return to Main Contents
NAMEtruncate, ftruncate - truncate a file to a specified length
DESCRIPTIONTruncate causes the file named by path or referenced by fd to be truncated to at most length bytes in size. If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is unspecified whether the file is left unchanged or is extended. In the latter case the extended part reads as zero bytes. With ftruncate, the file must be open for writing.
RETURN VALUEOn success, zero is returned. On error, -1 is returned, and errno is set appropriately.
CONFORMING TO4.4BSD, SVr4 (these function calls first appeared in BSD 4.2). SVr4 documents additional truncate error conditions EINTR, EMFILE, EMULTIHP, ENAMETOOLONG, ENFILE, ENOLINK, ENOTDIR. SVr4 documents for ftruncate additional EAGAIN and EINTR error conditions. POSIX has ftruncate but not truncate.
BUGSThese calls should be generalized to allow ranges of bytes in a file to be discarded.
This document was created by man2html, using the manual pages.
Time: 15:30:00 GMT, July 17, 2018