DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

chsize(S)


chsize -- changes the size of a file

Syntax

cc . . . -lx

int chsize (fildes, size)
int fildes;
long size;

Description

fildes is a file descriptor obtained from a creat, open, dup, fcntl, or pipe system call. chsize changes the size of the file associated with the file descriptor fildes to be exactly size bytes in length. The routine either truncates the file, or pads it with an appropriate number of bytes. If size is less than the initial size of the file, then all allocated disk blocks between size and the initial file size are freed.

The maximum file size as set by ulimit(S) is enforced when chsize is called, rather than on subsequent writes. Thus chsize fails, and the file size remains unchanged if the new changed file size would exceed the ulimit.

Return value

Upon successful completion, a value of 0 is returned. Otherwise, the value -1 is returned and errno is set to indicate the error.

Notes

In general if chsize is used to expand the size of a file, when data is written to the end of the file, intervening blocks are filled with zeros. In a few rare cases, reducing the file size may not remove the data beyond the new end-of-file. This routine must be linked with the linker option -lx.

See also

creat(S), dup(S), lseek(S), open(S), pipe(S), ulimit(S)

Standards conformance

chsize is an extension of AT&T System V provided by the Santa Cruz Operation.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003