*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> standard/truncate (2)              
Title
Content
Arch
Section
 

t(2)

Contents


TRUNCATE(2)							   TRUNCATE(2)


NAME    [Toc]    [Back]

     truncate, ftruncate, truncate64, ftruncate64 - set	a file to a specified
     length

C SYNOPSIS    [Toc]    [Back]

     #include <unistd.h>

     int truncate (const char *path<b>, off_t length<b>);

     int ftruncate (int	fildes<b>,	off_t length<b>);

     int truncate64 (const char	*path<b>, off64_t length<b>);

     int ftruncate64 (int fildes<b>, off64_t length<b>);

DESCRIPTION    [Toc]    [Back]

     The file whose name is given by path or referenced	by the descriptor
     fildes has	its size set to	length bytes.

     If	the file was previously	longer than length, bytes past length will no
     longer be accessible.  If it was shorter, bytes from the EOF before the
     call to the EOF after the call will be read in as zeros.  The effective
     user ID of	the process must have write permission for the file, and for
     ftruncate and ftruncate64 the file	must be	open for writing.

     The only difference between the regular routines and the *64 routines is
     that length is a 64-bit value for the *64 routines, allowing files	longer
     than 2 gigabytes in size to be truncated.	This is	relevant only on
     certain filesystem	types.

     truncate and truncate64 fail if one or more of the	following are true:

     EACCES	       Search permission is denied on a	component of the path
		       prefix.

     EACCES	       Write permission	is denied for the file referred	to by
		       path.

     EAGAIN	       The file	exists,	mandatory file/record locking is set,
		       and there are outstanding record	locks on the file [see
		       chmod(2)].  This	restriction is not currently enforced.

     EFAULT	       path points outside the process's allocated address
		       space.

     EFBIG	       An attempt is made to write a file that exceeds the
		       process's file size limit or the	maximum	file size [see
		       getrlimitINTR	       A signal	was caught during execution of the truncate or
		       truncate64 routine.




									Page 1






TRUNCATE(2)							   TRUNCATE(2)



     EINVAL	       path is not an ordinary file.

     EINVAL	       length is less than zero.

     EIO	       An I/O error occurred while reading from	or writing to
		       the file	system.

     EISDIR	       The file	referred to by path is a directory.

     ELOOP	       Too many	symbolic links were encountered	in translating
		       path.

     ENAMETOOLONG      The length of a path component exceeds {NAME_MAX}
		       characters, or the length of path exceeds {PATH_MAX}
		       characters.

     ENOENT	       Either a	component of the path prefix or	the file
		       referred	to by path does	not exist.

     ENOTDIR	       A component of the path prefix of path is not a
		       directory.

     EROFS	       The file	referred to by path resides on a read-only
		       file system.

     ETIMEDOUT	       The object of the write is located on a remote system
		       which is	not available [see intro(2)].

     ftruncate and ftruncate64 fail if one or more of the following are	true:

     EAGAIN	       The file	exists,	mandatory file/record locking is set,
		       and there are outstanding record	locks on the file [see
		       chmod(2)].  This	restriction is not currently enforced.

     EBADF	       fildes is not a file descriptor open for	writing.

     EFBIG	       An attempt is made to write a file that exceeds the
		       process's file size limit or the	maximum	file size [see
		       getrlimitINTR	       A signal	was caught during execution of the ftruncate
		       or ftruncate64 routine.

     EINVAL	       length is less than zero.

     EINVAL	       fildes does not correspond to an	ordinary file.

     EIO	       An I/O error occurred while reading from	or writing to
		       the file	system.






									Page 2






TRUNCATE(2)							   TRUNCATE(2)



     ETIMEDOUT	       The object of the write is located on a remote system
		       which is	not available [see intro(2)].

SEE ALSO    [Toc]    [Back]

      
      
     fcntl(2), getrlimit(2), open(2)

DIAGNOSTICS    [Toc]    [Back]

     Upon successful completion, a value of 0 is returned.  Otherwise, a value
     of	-1 is returned and errno is set	to indicate the	error.

BUGS    [Toc]    [Back]

     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.

     These calls should	be generalized to allow	ranges of bytes	in a file to
     be	discarded.


									PPPPaaaaggggeeee 3333
[ Back ]
 Similar pages
Name OS Title
truncate Linux truncate a file to a specified length
truncate NetBSD truncate a file to a specified length
ftruncate NetBSD truncate a file to a specified length
ftruncate HP-UX truncate a file to a specified length
ftruncate Tru64 Change file length
truncate Tru64 Change file length
truncate HP-UX truncate a file to a specified length
ftruncate FreeBSD truncate or extend a file to a specified length
truncate FreeBSD truncate or extend a file to a specified length
truncate OpenBSD truncate or extend a file to a specified length
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service