chsize()

change file size 

Function


SYNOPSIS

#include <unistd.h>

int chsize(int fildes, long size);


DESCRIPTION

The chsize() function changes the size of the file associated with the file descriptor fildes to be exactly size bytes in length. The function either truncates the file or pads it with an appropriate number of bytes. If chsize() fails, for example, because there is insufficient space, the file size remains unchanged.


PARAMETERS

fildes 

Is the file descriptor of a disk file opened with write access.

size 

Is the new file length, in bytes. If size is less than the initial size of the file, all allocated disk blocks between size and the initial file size are freed. If size is negative, then the file is truncated to zero length.


RETURN VALUES

If successful, chsize() returns a value of zero. On failure, it returns a value of -1 and sets errno to the following values:

EBADF 

File descriptor is not open.

EACCES 

File is not opened for writing.

EINVAL 

File descriptor is not for a disk file.

ENOSPC 

Insufficient space on device.


CONFORMANCE

SVR4


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

If chsize() is used to expand the size of a file, when data is written to the end of the file, the content of intervening blocks is undefined.

This function is deprecated; use ftruncate() or truncate() instead.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
creat(), ftruncate(), lseek(), open(), truncate()


PTC MKS Toolkit 10.3 Documentation Build 39.