Copyright (C) 2000-2012 |
Manpages TRUNCATESection: Linux Programmer's Manual (2)Updated: 1998-12-21 Index Return to Main Contents NAMEtruncate, ftruncate - truncate a file to a specified lengthSYNOPSIS#include <unistd.h>
int truncate(const char *path, off_t 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.ERRORSFor truncate:
For ftruncate:
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.The POSIX standard does not define what happens if the file has fewer bytes than length. BUGSThese calls should be generalized to allow ranges of bytes in a file to be discarded.SEE ALSOopen(2)
IndexThis document was created by man2html, using the manual pages. Time: 01:11:28 GMT, January 21, 2025 |