Open System Services System Calls Reference Manual (G06.25+, H06.03+)
System Functions (f - i) ftruncate(2)
NAME
ftruncate - Changes file length
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <sys/types.h>
int ftruncate(
int filedes,
off_t length);
PARAMETERS
filedes Specifies the descriptor of a file that must be open for writing.
length Specifies the new length of the file in bytes.
DESCRIPTION
The ftruncate() function changes the length of a file to the size, in bytes, specified by the length
parameter.
If the new length is less than the previous length, the ftruncate() function removes all data
beyond length bytes from the specified file. All file data between the new EOF (end-of-file) and
the previous EOF is discarded.
If the new length is greater than the previous length, zeros are added between the previous EOF
and the new EOF. If the new length would exceed the file size limit for the calling process, the
call to ftruncate() fails, and errno is set to [EINVAL].
Full blocks are returned to the fileset so that they can be used again, and the file size is changed
to the value of the length parameter.
The ftruncate() function has no effect on FIFO special files. This function does not modify the
seek pointer of the file. If ftruncate( ) is called for a FIFO, the call fails, and errno is set to
[EINVAL].
Upon successful completion, the ftruncate() function marks the st_ctime and st_mtime fields of
the file for update. If the file is a regular file, the ftruncate( ) function clears the S_ISUID and
S_ISGID attributes of the file.
RETURN VALUES
Upon successful completion, the value 0 (zero) is returned. Otherwise, the value -1 is returned
and errno is set to indicate the error.
ERRORS
If any of these conditions occurs, the ftruncate( ) function sets errno to the corresponding value:
[EBADF] The filedes parameter does not specify a valid file descriptor open for writing.
[EFBIG] The new file size would exceed the process’s file size limit or the maximum file
size.
[EINTR] The function was interrupted by a signal before any data arrived.
[EINVAL] One of these conditions occurred:
• The file pointed to by the filedes parameter is not a regular file.
• The value specified for the length parameter was less than 0 (zero).
527186-003 Hewlett-Packard Company 3−33