Path: utzoo!attcan!uunet!amdahl!kucharsk From: kucharsk@uts.amdahl.com (William Kucharski) Newsgroups: comp.unix.wizards Subject: Re: Atomic file truncation Summary: SYSV ftruncate(), take II Message-ID: <87=w02l0254301@amdahl.uts.amdahl.com> Date: 13 May 89 04:23:55 GMT References: Reply-To: kucharsk@amdahl.uts.amdahl.com (William Kucharski) Distribution: comp Organization: Amdahl Coup, UTS Products Hen House Lines: 40 This was posted before in a discussion about providing a work-alike of BSD ftruncate(2) in SYSV, but here goes again: The routine depends on the undocumented fcntl F_FREESP, which is present in SVR3.1 and above. The fcntl frees file space starting at the location indicated by fl.l_start. #include #include int truncate(fd, length) int fd; off_t length; { struct flock fl; /* truncate file to length */ fl.l_whence = 0; fl.l_len = 0; fl.l_start = length; /* make offset "start" the new EOF */ fl.l_type = F_WRLCK; /* why not write lock it? */ if (fcntl(fd, F_FREESP, &fl) < 0) return(-1); return(0); } -- William Kucharski ARPA: kucharsk@uts.amdahl.com UUCP: ...!{ames,decwrl,sun,uunet}!amdahl!kucharsk Disclaimer: The opinions expressed above are my own, and may not agree with those of any other sentient being, not to mention those of my employer. So there.