TRUNCATE(2) UNIX Programmer's Manual TRUNCATE(2) NAME truncate - truncate a file to a specified length SYNOPSIS truncate(path, length) char *path; off_t length; ftruncate(fd, length) int fd; off_t length; DESCRIPTION _T_r_u_n_c_a_t_e causes the file named by _p_a_t_h or referenced by _f_d to be truncated to at most _l_e_n_g_t_h bytes in size. If the file previously was larger than this size, the extra data is lost. With _f_t_r_u_n_c_a_t_e, the file must be open for writing. RETURN VALUES A value of 0 is returned if the call succeeds. If the call fails a -1 is returned, and the global variable _e_r_r_n_o speci- fies the error. ERRORS _T_r_u_n_c_a_t_e succeeds unless: [ENOTDIR] A component of the path prefix is not a directory. [EINVAL] The pathname contains a character with the high-order bit set. [ENAMETOOLONG] A component of a pathname exceeded 255 char- acters, or an entire path name exceeded 1023 characters. [ENOENT] The named file does not exist. [EACCES] Search permission is denied for a component of the path prefix. [EACCES] The named file is not writable by the user. [ELOOP] Too many symbolic links were encountered in translating the pathname. [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) Printed 11/26/99 March 29, 1986 1 TRUNCATE(2) UNIX Programmer's Manual TRUNCATE(2) file that is being executed. [EIO] An I/O error occurred updating the inode. [EFAULT] _P_a_t_h points outside the process's allocated address space. _F_t_r_u_n_c_a_t_e succeeds unless: [EBADF] The _f_d is not a valid descriptor. [EINVAL] The _f_d references a socket, not a file. [EINVAL] The _f_d is not open for writing. SEE ALSO open(2) BUGS These calls should be generalized to allow ranges of bytes in a file to be discarded. Printed 11/26/99 March 29, 1986 2