Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!network!ucsd!usc!cs.utexas.edu!ico!ico.isc.com!dougm From: dougm@queso.ico.isc.com (Doug McCallum) Newsgroups: comp.unix.questions Subject: Re: Set file size in SYSV Message-ID:Date: 14 Aug 89 15:31:38 GMT References: <708@msa3b.UUCP> <10723@smoke.BRL.MIL> Sender: news@ico.ISC.COM Reply-To: dougm@ico.isc.com Organization: INTERACTIVE Systems Corporation Lines: 29 In-reply-to: gwyn@smoke.BRL.MIL's message of 13 Aug 89 00:14:32 GMT In article <10723@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: In article <708@msa3b.UUCP> kevin@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@ico.isc.com