delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/07/21/04:01:44

Date: Wed, 21 Jul 1999 10:59:20 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Alain Magloire <alainm AT rcsm DOT ece DOT mcgill DOT ca>
cc: djgpp-workers AT delorie DOT com
Subject: Re: ftruncate
In-Reply-To: <199907201418.KAA23375@mccoy2.ECE.McGill.CA>
Message-ID: <Pine.SUN.3.91.990721105900.7757H-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 20 Jul 1999, Alain Magloire wrote:

> I'm not sure I follow, so you are saying if I want to shrink a file, 
> I can do that by lseek()ing back and write() 0 byte ?

Yes.  But it's not a 0 byte, it's zero bytes.  That is, you tell DOS
to write zero bytes to the file.  Instead of interpreting this as a
no-op, DOS shrinks the file's size to the current file pointer
position.  Amazingly enough, it's not a bug, it's a feature ;-).

> To do this on Un*x I got to use ftruncate();

I know.  But DOS doesn't have a special system call for that, so DJGPP
uses the seek/write-zero way to emulate it.  (Now it also seeks back
before returning.)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019