chsize(S-osr5)
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-osr5)
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-osr5),
dup(S-osr5),
lseek(S-osr5),
open(S-osr5),
pipe(S-osr5),
ulimit(S-osr5)
Standards conformance
chsize is an extension of AT&T System V provided by the
Santa Cruz Operation.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005