diff options
author | Guido van Rossum <guido@python.org> | 2001-09-10 20:43:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-10 20:43:35 (GMT) |
commit | 8b4e43e768f3f49513f6f32f20ecb6478c1ad840 (patch) | |
tree | b13b0ab05dbf27f47d0e858cfe85b11d411b305d /Objects/fileobject.c | |
parent | c4c062f5071d1c457074cee8a7b372743a028a1a (diff) | |
download | cpython-8b4e43e768f3f49513f6f32f20ecb6478c1ad840.zip cpython-8b4e43e768f3f49513f6f32f20ecb6478c1ad840.tar.gz cpython-8b4e43e768f3f49513f6f32f20ecb6478c1ad840.tar.bz2 |
_portable_fseek():
Subtlety on Windows: if we change test_largefile.py to use a file
> 4GB, it still fails. A debug session suggests this is because
fseek(fp, 0, 2) refuses to seek to the end of the file when the file
is > 4GB, because it uses the SetFilePointer() in 32-bit mode.
But it only fails when we seek relative to the end of the file,
because in the other seek modes only calls to fgetpos() and fsetpos()
are made, which use Get/SetFilePointer() in 64-bit mode. Solution:
#ifdef MS_WInDOWS, replace the call to fseek(fp, ...) with a call to
_lseeki64(fileno(fp), ...). Make sure to call fflush(fp) first.
(XXX Could also replace the entire branch with a call to _lseeki64().
Would that be more efficient? Certainly less generated code.)
(XXX This needs more testing. I can't actually test that it works for
files >4GB on my Win98 machine, because the filesystem here won't let
me create files >=4GB at all. Tim should test this on his Win2K
machine.)
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 5909e99..c8e3ae4 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -239,8 +239,14 @@ _portable_fseek(FILE *fp, Py_off_t offset, int whence) fpos_t pos; switch (whence) { case SEEK_END: +#ifdef MS_WINDOWS + fflush(fp); + if (_lseeki64(fileno(fp), 0, 2) == -1) + return -1; +#else if (fseek(fp, 0, SEEK_END) != 0) return -1; +#endif /* fall through */ case SEEK_CUR: if (fgetpos(fp, &pos) != 0) |