TRUNCATE(2) System Calls TRUNCATE(2)
truncate, ftruncate - truncate a file to a specified length
int truncate (const char *path, off_t length);
int ftruncate (int fd, off_t length);
truncate causes the file named by path or referenced by fd to be trun-
cated to at most length bytes in size. If the file previously was
larger than this size, the extra data is lost. With ftruncate, the
file must be open for writing.
A value of 0 is returned if the call succeeds. If the call fails a -1
is returned, and the global variable errno specifies the error.
The GNO implementation of truncate requires that the file must be able
to be opened for writing. If this is not possible, truncate returns -1
and sets errno.
These calls should be generalized to allow ranges of bytes in a file to
The ftruncate function call appeared in 4.2BSD.
GNO 24 January 1997 TRUNCATE(2)
Man(1) output converted with