summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-26 17:19:33 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-26 17:19:33 (GMT)
commit57233cb3f9d59233711e63034cc1e84360f0da15 (patch)
treeaed14b8894966fc10eb1e848314c1898cb903748 /Modules
parent61ec0d32634eaa43bbe433628607c137d91736de (diff)
downloadcpython-57233cb3f9d59233711e63034cc1e84360f0da15.zip
cpython-57233cb3f9d59233711e63034cc1e84360f0da15.tar.gz
cpython-57233cb3f9d59233711e63034cc1e84360f0da15.tar.bz2
Patch 1330 by Christian Heimes (with some TLC applied by myself).
Move most of the messiness with truncate() on Windows into _fileio.c. Still keep the flush() call in io.py though.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_fileio.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 7757af9..bc707e8 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -628,14 +628,21 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
so don't even try using it. */
{
HANDLE hFile;
- PyObject *pos2;
+ PyObject *pos2, *oldposobj;
+
+ /* store the current position */
+ oldposobj = portable_lseek(self->fd, NULL, 1);
+ if (oldposobj == NULL) {
+ Py_DECREF(posobj);
+ return NULL;
+ }
/* Have to move current pos to desired endpoint on Windows. */
errno = 0;
pos2 = portable_lseek(fd, posobj, SEEK_SET);
- if (pos2 == NULL)
- {
+ if (pos2 == NULL) {
Py_DECREF(posobj);
+ Py_DECREF(oldposobj);
return NULL;
}
Py_DECREF(pos2);
@@ -651,6 +658,18 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
errno = EACCES;
}
Py_END_ALLOW_THREADS
+
+ if (ret == 0) {
+ /* Move to the previous position in the file */
+ pos2 = portable_lseek(fd, oldposobj, SEEK_SET);
+ if (pos2 == NULL) {
+ Py_DECREF(posobj);
+ Py_DECREF(oldposobj);
+ return NULL;
+ }
+ }
+ Py_DECREF(pos2);
+ Py_DECREF(oldposobj);
}
#else
Py_BEGIN_ALLOW_THREADS