ftruncate forcibly sets the size of the file referred to by
fd to filesize. If this expands the file, the new
data appears as if it is zero-filled. If this shrinks the file, the
excess data is discarded.
The file must be open for write.
Return Values
On success, ftruncate returns 0. On error, -1 is returned, and
errno is set according to the error
encountered.
Errors
The following error codes should be returned under the conditions
given. Other error codes may be returned for other errors not
mentioned here.
EBADF
fd is not a valid file handle, or
it is not open for writing.