truncate(2) truncate(2)NAME truncate, ftruncate - truncate a file to a specified length SYNOPSIS int truncate(path, length) char *path; int length; int ftruncate(fd, length) int fd, length; DESCRIPTION truncate 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. STATUS MESSAGES AND VALUES 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. The truncate program will fail if: EPERM The pathname contains a character with the high-order bit set. ENOENT The pathname was too long. ENOTDIR A component of the path prefix of path is not a directory. EPERM A pathname contains a character with the high-order bit set. ENAMETOOLONG A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX. ELOOP Too many symbolic links were encountered in translating a pathname. ENOENT The named file does not exist. EACCES A component of the path prefix denies search January 1992 1
truncate(2) truncate(2)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 (shared text) file that is being executed. Note: If you are running an NFS system and you are accessing a shared binary remotely, it is possible that you will not get this errno. EFAULT name points outside the process's allocated address space. ftruncate will fail if: EBADF The fd is not a valid descriptor. EINVAL The fd references a socket, not a file. LIMITATIONS Partial blocks discarded as the result of truncation are not zero filled; this can cause holes in files which do not read as zero. These calls should be generalized to allow ranges of bytes in a file to be discarded. SEE ALSO open(2) 2 January 1992