ftruncate
ftruncate is a POSIX function that truncates or extends the size of the file associated with a given open file descriptor. It operates on the file described by the descriptor and is declared in unistd.h. The function returns 0 on success and -1 on error, with errno set to indicate the failure.
If the new length is smaller than the current size, the file is truncated to that length.
The file descriptor passed to ftruncate must refer to a file that supports resizing. It typically cannot
Prototype and usage: int ftruncate(int fd, off_t length); length is an off_t value representing the new size.
See also: truncate, file descriptor manipulation, and related filesystem resizing operations.