truncate(2)
NAME
truncate, ftruncate − truncate a file to a specified length
SYNTAX
truncate(path, length)
char *path;
int length;
ftruncate(fd, length)
int fd, length;
DESCRIPTION
The truncate system call causes the file named by path or referenced by fd to be truncated 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.
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.
RESTRICTIONS
Partial blocks discarded as the result of truncation are not zero filled; this can result in holes in files which do not read as zero.
DIAGNOSTICS
The truncate system call succeeds unless:
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied for a component of the path prefix.
[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 (shared text) file that is being executed.
[EFAULT] The path points outside the process’s allocated address space.
[EINVAL] The pathname contains a character with the high-order bit set.
[ENAMETOOLONG]
A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.
[ELOOP] Too many symbolic links were encountered in translating the pathname.
[EIO] An I/O error occurred updating the inode.
The ftruncate system call succeeds unless:
[EBADF] The fd is not a valid descriptor.
[EINVAL] The fd references a socket, not a file.
[ETIMEDOUT] A "connect" request or remote file operation failed because the connected party did not properly respond after a period of time which is dependent on the communications protocol.