.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)truncate.2 6.9 (Berkeley) 3/10/91 .\" .\" Modified Sat Jul 24 12:46:33 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Tue Oct 22 22:36:33 1996 by Eric S. Raymond .\" .TH TRUNCATE 2 "24 July 1993" "BSD Man Page" "Linux Programmer's Manual" .SH NAME truncate, ftruncate \- truncate a file to a specified length .SH SYNOPSIS .B #include .sp .BI "int truncate(const char *" path ", size_t " length ); .br .BI "int ftruncate(int " fd ", size_t " length ); .SH DESCRIPTION .B Truncate causes the file named by .I path or referenced by .I fd to be truncated to at most .I length bytes in size. If the file previously was larger than this size, the extra data is lost. With .BR ftruncate , the file must be open for writing. .SH "RETURN VALUE" On success, zero is returned. On error, \-1 is returned, and .I errno is set appropriately. .SH ERRORS For .BR truncate : .TP 0.8i .B ENOTDIR A component of the path prefix is not a directory. .TP .B EINVAL The pathname contains a character with the high-order bit set. .TP .B ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .TP .B ENOENT The named file does not exist. .TP .B EACCES Search permission is denied for a component of the path prefix. .TP .B EACCES The named file is not writable by the user. .TP .B ELOOP Too many symbolic links were encountered in translating the pathname. .TP .B EISDIR The named file is a directory. .TP .B EROFS The named file resides on a read-only file system. .TP .B ETXTBSY The file is a pure procedure (shared text) file that is being executed. .TP .B EIO An I/O error occurred updating the inode. .TP .B EFAULT .I Path points outside the process's allocated address space. .PP For .BR Ftruncate : .TP 0.8i .B EBADF The .I fd is not a valid descriptor. .TP .B EINVAL The .I fd references a socket, not a file. .TP .B EINVAL The .I fd is not open for writing. .SH "CONFORMING TO" 4.4BSD, SVr4 (these function calls first appeared in BSD 4.2). SVr4 documents additional .B truncate error conditions EINTR, EMFILE, EMULTIHP, ENAMETOOLONG, ENFILE, ENOLINK, ENOTDIR. SVr4 .B ftruncate documents additional EAGAIN and EINTR error conditions. .SH BUGS These calls should be generalized to allow ranges of bytes in a file to be discarded. .SH "SEE ALSO" .BR open (2)