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

  man pages->Linux man pages -> truncate (2)              



NAME    [Toc]    [Back]

       truncate, ftruncate - truncate a file to a specified length

SYNOPSIS    [Toc]    [Back]

       #include <unistd.h>

       int truncate(const char *path, off_t length);
       int ftruncate(int fd, off_t length);

DESCRIPTION    [Toc]    [Back]

       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.	If the file previously
       was shorter, it is unspecified whether the file is left unchanged or is
       extended.  In  the  latter  case the extended part reads as zero bytes.
       With ftruncate, the file must be open for writing.

RETURN VALUE    [Toc]    [Back]

       On success, zero is returned.  On error, -1 is returned, and  errno  is
       set appropriately.

ERRORS    [Toc]    [Back]

       For truncate:

       ENOTDIR    [Toc]    [Back]
	      A component of the path prefix is not a directory.

       ENAMETOOLONG    [Toc]    [Back]
	      A  component of a pathname exceeded 255 characters, 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

       EISDIR The named file is a directory.

       EROFS  The named file resides on a read-only file system.

       ETXTBSY    [Toc]    [Back]
	      The file is a pure procedure (shared text) file  that  is  being

       EIO    An I/O error occurred updating the inode.

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

       For ftruncate:

       EBADF  The fd is not a valid descriptor.

       EINVAL The fd references a socket, not a file.

       EINVAL The fd is not open for writing.

CONFORMING TO    [Toc]    [Back]

       4.4BSD,	SVr4  (these  function calls first appeared in BSD 4.2).  SVr4
       documents additional truncate error conditions EINTR, EMFILE, EMULTIHP,
       ENAMETOOLONG,  ENFILE,  ENOLINK, ENOTDIR.  SVr4 documents for ftruncate
       additional EAGAIN and EINTR error conditions.  POSIX has ftruncate  but
       not truncate.

       The  POSIX  standard does not define what happens if the file has fewer
       bytes than length.

BUGS    [Toc]    [Back]

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

SEE ALSO    [Toc]    [Back]


				  1998-12-21			   TRUNCATE(2)
[ Back ]
 Similar pages
Name OS Title
truncate FreeBSD truncate or extend a file to a specified length
ftruncate FreeBSD truncate or extend a file to a specified length
truncate OpenBSD truncate or extend a file to a specified length
ftruncate OpenBSD truncate or extend a file to a specified length
truncate FreeBSD truncate or extend the length of files
truncate IRIX set a file to a specified length
truncate Tru64 Change file length
ftruncate Tru64 Change file length
vxresize HP-UX change the length of a volume containing a file system
uitrunc Tru64 truncate a floating-point number
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service