TRUNCATE(2)
NAME
truncate − truncate a file to a specified length
USAGE
truncate(path, length) char *path; int length;
ftruncate(fd, length) int fd, length;
DESCRIPTION
Truncate truncates the file named by path to a maximum of length bytes in size. Ftruncate does the same thing for the file referenced by fd, which must be open for writing.
If the file was larger than length, the extra data is lost.
NOTES
Partial blocks discarded as the result of truncation are not zero-filled; this can leave holes in files which do not read as zero.
RETURN VALUE
A successful call returns zero. A failed call returns -1 and sets errno as indicated below.
ERRORS
Truncate succeeds unless:
[EPERM] The pathname contains a character with the high-order bit set.
[ENOENT] The pathname is too long.
[ENOTDIR] A component of the path prefix of path is not a directory.
[ENOENT] The named file does not exist.
[EACCES] A component of the path prefix denies search permission.
[EISDIR] The named file is a directory.
[EROFS] The named file resides on a read-only file system.
[ETXTBSY] The file is a pure procedure (i.e., shared text) file that is being executed.
[EFAULT] Path points outside the process’s allocated address space.
Ftruncate succeeds unless:
[EBADF] Fd is not a valid descriptor.
[EINVAL] Fd refers to a socket, not a file.