ftruncate(), ftruncate64()

set file to specified length 

Function


SYNOPSIS

#include <unistd.h>

int ftruncate(int fildes, off_t length);

int ftruncate64(int fildes, off64_t length);


DESCRIPTION

The ftruncate() function sets a file to a specified length. Specifically, ftruncate() sets the size of the file referenced by the descriptor fildes to length bytes.

If the file was previously longer than length, bytes past length are lost. If the file was shorter, bytes between the old and the new length are read in as zeros. The effective user ID of the process must have write permission for the file, and the file must be open for writing.

These functions do not modify the file offset for any open file descriptors associated with the file. On successful completion, if the file size is changed, these functions mark the st_ctime and st_mtime fields of the file for update.

The ftruncate64() function is identical to the ftruncate() function except that it is capable of manipulating files that are larger than 2 gigabytes. The lftruncate64() function is a part of the large file extensions.


PARAMETERS

fildes 

Is the file descriptor for the file to be truncated.

length 

Is the new file size.


RETURN VALUES

If successful, ftruncate() returns zero. On failure, it returns -1 and sets errno to one of the following values:

EBADF 

fildes is not a file descriptor that is open for writing.

EFBIG 

The file is a regular file and its length is greater than the offset maximum established in the open file description associated with fildes.

EINTR 

A signal interrupted the call.

EINVAL 

The length argument was less than 0.

The fildes argument references a file that was opened without write permission.

EINVAL 

fildes does not correspond to an ordinary file.

ETXTBSY 

The file exists, mandatory file/record locking is set, and there are outstanding record locks on the file.


CONFORMANCE

UNIX 98.

ftruncate64(): Large File Specification, revision 1.5.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
open(), truncate()

Miscellaneous:
lf64


PTC MKS Toolkit 10.5 Documentation Build 40.