Changes file length to a specified length in bytes.
#include <unistd.h> int truncate (const char *path, off_t length);
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.)
0 | Indicates success. |
-1 | An error occurred; errno is set to indicate the error. |