]> granicus.if.org Git - python/commit
SF bug 801631: file.truncate fault on windows.
authorTim Peters <tim.peters@gmail.com>
Sun, 7 Sep 2003 03:30:18 +0000 (03:30 +0000)
committerTim Peters <tim.peters@gmail.com>
Sun, 7 Sep 2003 03:30:18 +0000 (03:30 +0000)
commitf1827cfaab46e4d9137fd72543c83977eba50cb0
treea9eff73415e1950bd2448402d3d2db842d66cad0
parenta26c16c821461986e08ddd63a60da42150180606
SF bug  801631:  file.truncate fault on windows.

file_truncate():  C doesn't define what fflush(fp) does if fp is open
for update, and the preceding I/O operation on fp was input.  On Windows,
fflush() actually changes the current file position then.  Because
Windows doesn't support ftruncate() directly, this not only caused
Python's file.truncate() to change the file position (contra our docs),
it also caused the file not to change size.

Repaired by getting the initial file position at the start, restoring
it at the end, and tossing all the complicated micro-efficiency checks
trying to avoid "provably unnecessary" seeks.  file.truncate() can't
be a frequent operation, and seeking to the current file position has
got to be cheap anyway.

Bugfix candidate.
Lib/test/test_file.py
Misc/NEWS
Objects/fileobject.c