Re: how truncate a file in C?
From: Joe Halpin (jhalpin_at_nortelnetworks.com_.nospam)
Date: 17 Jun 2003 09:16:53 -0500
Valentin Nechayev <email@example.com> writes:
> >>> Frank Cusack wrote:
> > MR>> True, but truncating a file opened as a FILE would have an unpredictable
> > MR>> effect on further I/O with the FILE.
> >> IMO fflush() before truncating and fseek() after it help from unpredictability.
> FC> fflush() guarantees nothing here.
> Citing SUSv3:
> fflush() shall cause any unwritten data for that stream to be written
> to the file,
> FC> You cannot mix stdio and system I/O
> FC> predictably, period.
> You didn't show any arguments for this words.
> FC> The effects of interchanging the calls are
> FC> system dependent,
> Where is it written? Please show.
SUS3 isn't quite as absolute as the above, but it does give some rules
for defined interaction between stdio streams and file descriptors,
see 'Interaction of File Descriptors and Standard I/O Streams" in
If these rules aren't followed, the results are unspecified.