Set file size in SYSV
Doug McCallum
dougm at queso.ico.isc.com
Tue Aug 15 01:31:38 AEST 1989
In article <10723 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
In article <708 at msa3b.UUCP> kevin at msa3b.UUCP (Kevin P. Kleinfelter) writes:
>O.K. I give up. How do you set the size of a file in SYSV.
>In particular, I want to take a file which is 1000 bytes, and truncate
>it to 500 bytes WITHOUT COPYING IT.
Not possible in UNIX System V through SVR3.2, probably supported in SVR4.0.
You can simulate this operation by snarfing the intended ultimate file
contents somewhere safe (like an in-memory array, if it will fit, or
a temp file), then use creat() to truncate the file to 0 length, then
write back the desired final contents.
While not documented in the fcntl man page or listed in the fcntl man
page with 386/ix, the XENIX compatibility of V.3.2 provides the
"chsize" call in the XENIX compatibility library (-lx) and the
F_CHSIZE fcntl function which are basically "ftruncate". using
chsize(fd, size) does what ftruncate would do.
#define ftruncate(fd,size) fcntl(fd, F_CHSIZE, size)
will work if you don't want to load the XENIX library.
So, from V.3.2 on there is likely to be something equivalent to
ftruncate.
Doug McCallum
Interactive Systems Corp.
dougm at ico.isc.com
More information about the Comp.unix.questions
mailing list