Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

ftruncate(2) OSS System Calls Reference Manual
NAME
ftruncate - Changes file length
LIBRARY
G-series native OSS processes: system library
H-series and J-series OSS processes: implicit libraries
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
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.
When the function is thread-aware, specifies an open file descriptor obtained
from a successful call to the creat(), creat64(), dup(), open(),oropen64()
function, or the thread-aware dup2( ) or fcntl( ) function.
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 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.
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 First-in, First-out (FIFO) special files. This function
does not modify the seek pointer of the file. If ftruncate() is called for a FIFO file, 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.
Use From a Threaded Application
The thread-aware ftruncate() function offers an alternative to the O_SYNC file status flag.
Using thread-aware ftruncate( ) gives a threaded application control over the performance trade
offs involved in guaranteeing data integrity. OSS file-system caching can be used for files that
are protected only by thread-aware ftruncate( ) function calls.
If this function must wait for an I/O operation to complete on an open file, this function blocks
the thread (instead of the entire process) that called it, while it waits for the I/O operation to com-
plete.
364 Hewlett-Packard Company 527186-023