This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Truncate a file to a specified length
#include <unistd.h> int truncate( const char* path, off_t length );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The truncate() function causes the regular file named by path to have a size of length bytes.
The effect of truncate() on other types of files is unspecified. If the file previously was larger than length, the extra data is lost. If it was previously shorter than length, bytes between the old and new lengths are read as zeroes. The process must have write permission for the file.
If the request would cause the file size to exceed the soft file size limit for the process, the request fails and the implementation generates the SIGXFSZ signal for the process.
This function doesn't modify the file offset for any open file descriptions associated with the file. On successful completion, if the file size is changed, truncate() marks for update the st_ctime and st_mtime fields of the file, and if the file is a regular file, the S_ISUID and S_ISGID bits of the file mode may be cleared.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
chmod(), fcntl(), ftruncate(), open()