The ftruncate(2) function truncates the file
referenced by fd to at most length bytes in size. The
truncate(2) call also truncates a file, but the
file is specified by the pathname path.
If the file previously was larger than length, the extra
data is lost. If the file was shorter, the extra space is filled
with zeroes.
For ftruncate, the file described by fd must have
been opened for writing. For truncate, the calling process
must simply have write permission on the file.
Calling truncate(2) or ftruncate(2) on an open file
won't affect any file offsets associated with file descriptors for
that file.
If the file size is actually changed, the st_ctime and
st_mtime fields are marked for change. The s_ISUID and the
S_ISGID bits on the file permission will be cleared.
Some directory component of path denied search
permission to the process, or the process didn't have write
permission on the file.
[EFBIG]
The length argument was longer than the maximum file
size.
[EINTR]
The call was interrupted by a signal.
[EINVAL]
The length argument was less than 0.
[EIO]
An I/O error occurred while reading or writing to a file
system.
[EISDIR]
The path ends in a directory.
[ELOOP]
Too many symbolic links were encountered while resolving
path.
[ENAMETOOLONG]
The total length of the path was longer than {PATH_MAX},
or the length of some component of path was longer than
{NAME_MAX}, or the resolution of a symbolic link produced an
intermediate result that was longer than {PATH_MAX}.
[ENOENT]
Either path was an empty string, or some component of
path named a nonexistent file.
[ENOTDIR]
Some component of the path prefix of path is not a
directory.
[EROFS]
The file named by path is on a read-only
filesystem.