TRUNCATE(2) System Calls TRUNCATE(2)
NAME
truncate, ftruncate - truncate a file to a specified length
SYNOPSIS
#include <unistd.h>
int truncate (const char *path, off_t length);
int ftruncate (int fd, off_t length);
DESCRIPTION
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.
RETURN VALUES
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.
SEE ALSO
open(2)
BUGS
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
be discarded.
HISTORY
The ftruncate function call appeared in 4.2BSD.
GNO 24 January 1997 TRUNCATE(2)
Man(1) output converted with
man2html