[Python-Dev] Why do we flush before truncating?
Neil Schemenauer
nas-python at python.ca
Sat Sep 6 12:23:40 EDT 2003
On Sat, Sep 06, 2003 at 01:11:14PM -0400, Tim Peters wrote:
> I don't understand why we're flushing the file. ftruncate() isn't a
> standard C function, so the standard sheds no light on why we might be doing
> that.
The fflush call as been there forever. The truncate method was added
in 2.36 by Guido. I think the code was actually from Jim Roskind:
http://groups.google.com/groups?selm=199412070213.SAA06932%40infoseek.com
He says:
Note that since the underlying ftruncate operates on a file
descriptor (believe it or not), it was necessary to fflush() the
stream before performing the truncate. I thought about doing a
seek() as well, but could not find compelling reason to move the
stream pointer.
That still gives me no clue as to why the fflush() was deemed
necessary. I found this posting:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=35E0DB62.1BDD2D30%40taraz.kz&rnum=1
but, AFACK, the reason the program is not working the way the poster
expects is the missing fflush() call before the lseek() call (not
the fflush() before the ftruncate()).
Neil
More information about the Python-Dev
mailing list