Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site turtlevax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!pesnta!amd!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.unix-wizards Subject: Re: truncating a file opened via open() Message-ID: <786@turtlevax.UUCP> Date: Mon, 10-Jun-85 19:46:54 EDT Article-I.D.: turtleva.786 Posted: Mon Jun 10 19:46:54 1985 Date-Received: Tue, 11-Jun-85 08:28:24 EDT References: <340@cmu-cs-edu1.ARPA> Reply-To: ken@turtlevax.UUCP (Ken Turkowski) Organization: CADLINC, Inc. @ Menlo Park, CA Lines: 20 In article <340@cmu-cs-edu1.ARPA> hua@cmu-cs-edu1.ARPA (Ernest Hua) writes: >Does anyone have any idea how to truncate a file at the current point in >writing if it is opened by open()? I cannot use creat() because the file >is being used by another process, and I cannot use unlink() it is likely >that it is linked. If the updated contents is longer than the original, >it is not a problem because the file length is just extended. But if the >updated contents is shorter, the file does not shrink. We have 4.1BSD on >several 780's and 750's. try size = lseek(fd, 0L, 1); /* tell(fd) */ ftruncate(fd, size); /* int fd, size; */ It's yet another undocumented feature on 4.2. -- Ken Turkowski @ CADLINC, Menlo Park, CA UUCP: {amd,decwrl,hplabs,nsc,seismo,spar}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.ARPA