delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/04/30/04:57:39

From: alane AT wozzle DOT linet DOT org
Subject: Truncating a file
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Thu, 29 Apr 1993 09:46:27 +0000 (EDT)

> I've been investigating the trucate bug I posted on earlier,
> and after looking through a description of the DOS system calls,
> came to the conclusion that the only way you can truncate a file
> is using FCB functions. Can anyone confirm that ?

Uh, well, yes I can confirm that your information is incorrect. I
_know_ this is gonna sound weird, BUT ...

void trunc(int fd, long where)
{
    fseek(fd,where,SEEK_SET);
    write(fd,(void*)0,0);
}
	
this little trick can make for interesting error conditions when
otherwise healthy programs decide to write zero bytes to a file
for some stupid reason :-)

-- 
J. Alan Eldridge (alane AT wozzle DOT linet DOT org)
                 (also on Fidonet: 1:272/38.473)

- Raw text -


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