CHSIZE(S) XENIX System V CHSIZE(S)
Name
chsize - Changes the size of a file.
Syntax
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.
See Also
creat(S), dup(S), lseek(S), open(S), pipe(S), ulimit(S)
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.
Page 1 (printed 8/7/87)