truncate

Changes file length to a specified length in bytes.

Format

#include  <unistd.h>

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

Arguments

path
The name of a file that is to be truncated. This argument must point to a pathname that names a regular file for which the calling process has write permission.
length
The new length of the file in bytes.

Description

This function changes the length of a file to the size in bytes specified by the length argument.

If the new length is less than the previous length, the function removes all data beyond length bytes from the specified file. All file data between the new End-of-File and the previous End-of-File is discarded.

For stream files, if the new length is greater than the previous length, new file data between the previous End-of-File and the new End-of-File is added, consisting of all zeros. (For record files, it is not possible to extend the file in this manner.)

Return Values
Indicates success. 
-1  An error occurred; errno is set to indicate the error. 


Previous Page | Next Page | Table of Contents | Index