truncate(), truncate64()

set file to specified length 

Function


SYNOPSIS

#include <unistd.h>

int truncate(const char *pathname, off_t length);

int truncate64(const char *pathname, off64_t length);


DESCRIPTION

The truncate() function sets a file to a specified length. Specifically, truncate() sets the size of the file whose name is given by pathname 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.

The truncate64() function is identical to the truncate() function except that it is capable of manipulating files that are larger than 2 gigabytes.


PARAMETERS

pathname 

Is a pointer to a file.

length 

Is the new file size.


RETURN VALUES

If successful, truncate() and truncate64() return a value of zero. On failure, they return -1 and set errno to one of the following values:

EACCES 

A component of the path prefix denies search permission, or write permission is denied on the file.

EINTR 

A signal interrupted the call.

EINVAL 

The length argument was less than 0.

EISDIR 

The named file is a directory.

ENOENT 

A component of pathname does not name an existing file, or pathname is an empty string.

ENOTDIR 

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

ETXTBSY 

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

The file referred to by pathname is a pure procedure (shared text) file that is being executed.


CONFORMANCE

UNIX 98.

truncate64(): 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:
fcntl(), ftruncate(), open()

Miscellaneous:
lf64


PTC MKS Toolkit 10.5 Documentation Build 40.