xref: /csrg-svn/lib/libc/sys/truncate.2 (revision 61186)
1*61186Sbostic.\" Copyright (c) 1983, 1991, 1993
2*61186Sbostic.\"	The Regents of the University of California.  All rights reserved.
320277Smckusick.\"
443568Strent.\" %sccs.include.redist.man%
520277Smckusick.\"
6*61186Sbostic.\"     @(#)truncate.2	8.1 (Berkeley) 06/04/93
738053Sbostic.\"
847208Scael.Dd
947208Scael.Dt TRUNCATE 2
1047208Scael.Os BSD 4.2
1147208Scael.Sh NAME
1247208Scael.Nm truncate ,
1347208Scael.Nm ftruncate
1447208Scael.Nd truncate a file to a specified length
1547208Scael.Sh SYNOPSIS
1647208Scael.Fd #include <unistd.h>
1747208Scael.Ft int
1847208Scael.Fn truncate "const char *path" "off_t length"
1947208Scael.Ft int
2047208Scael.Fn ftruncate "int fd" "off_t length"
2147208Scael.Sh DESCRIPTION
2247208Scael.Fn Truncate
2320277Smckusickcauses the file named by
2447208Scael.Fa path
2520277Smckusickor referenced by
2647208Scael.Fa fd
2720277Smckusickto be truncated to at most
2847208Scael.Fa length
2920277Smckusickbytes in size.  If the file previously
3020277Smckusickwas larger than this size, the extra data
3120277Smckusickis lost.
3220277SmckusickWith
3347208Scael.Fn ftruncate ,
3420277Smckusickthe file must be open for writing.
3547208Scael.Sh RETURN VALUES
3620277SmckusickA value of 0 is returned if the call succeeds.  If the call
3747208Scaelfails a -1 is returned, and the global variable
3847208Scael.Va errno
3920277Smckusickspecifies the error.
4047208Scael.Sh ERRORS
4147208Scael.Fn Truncate
4220277Smckusicksucceeds unless:
4347208Scael.Bl -tag -width [ENOTDIR]
4447208Scael.It Bq Er ENOTDIR
4521004SmckusickA component of the path prefix is not a directory.
4647208Scael.It Bq Er EINVAL
4720277SmckusickThe pathname contains a character with the high-order bit set.
4847208Scael.It Bq Er ENAMETOOLONG
4921004SmckusickA component of a pathname exceeded 255 characters,
5021004Smckusickor an entire path name exceeded 1023 characters.
5147208Scael.It Bq Er ENOENT
5220277SmckusickThe named file does not exist.
5347208Scael.It Bq Er EACCES
5421004SmckusickSearch permission is denied for a component of the path prefix.
5547208Scael.It Bq Er EACCES
5626963SlepreauThe named file is not writable by the user.
5747208Scael.It Bq Er ELOOP
5821004SmckusickToo many symbolic links were encountered in translating the pathname.
5947208Scael.It Bq Er EISDIR
6020277SmckusickThe named file is a directory.
6147208Scael.It Bq Er EROFS
6220277SmckusickThe named file resides on a read-only file system.
6347208Scael.It Bq Er ETXTBSY
6420277SmckusickThe file is a pure procedure (shared text) file that is being executed.
6547208Scael.It Bq Er EIO
6621004SmckusickAn I/O error occurred updating the inode.
6747208Scael.It Bq Er EFAULT
6847208Scael.Fa Path
6920277Smckusickpoints outside the process's allocated address space.
7047208Scael.El
7147208Scael.Pp
7247208Scael.Fn Ftruncate
7320277Smckusicksucceeds unless:
7447208Scael.Bl -tag -width [ENOTDIR]
7547208Scael.It Bq Er EBADF
7620277SmckusickThe
7747208Scael.Fa fd
7820277Smckusickis not a valid descriptor.
7947208Scael.It Bq Er EINVAL
8020277SmckusickThe
8147208Scael.Fa fd
8220277Smckusickreferences a socket, not a file.
8347208Scael.It Bq Er EINVAL
8426963SlepreauThe
8547208Scael.Fa fd
8626963Slepreauis not open for writing.
8747208Scael.El
8847208Scael.Sh SEE ALSO
8947208Scael.Xr open 2
9047208Scael.Sh BUGS
9120277SmckusickThese calls should be generalized to allow ranges
9220277Smckusickof bytes in a file to be discarded.
9347208Scael.Sh HISTORY
9447208ScaelThe
9547208Scael.Nm
9647208Scaelfunction call appeared in
9747208Scael.Bx 4.2 .
98