summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-06-06 16:31:14 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-06-06 16:31:14 (GMT)
commit3a77c7ab16d737a19cfb3fae4bd0f92517abe149 (patch)
treea106a1d6a89baf1d9077e49ca78081123fc42b93 /Modules
parentfee1af9d1cf1836113e61e41acd8e913736644a1 (diff)
downloadcpython-3a77c7ab16d737a19cfb3fae4bd0f92517abe149.zip
cpython-3a77c7ab16d737a19cfb3fae4bd0f92517abe149.tar.gz
cpython-3a77c7ab16d737a19cfb3fae4bd0f92517abe149.tar.bz2
If append mode is specified seek to the end of the file.
Add a test to test_fileio.py for this.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_fileio.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index c46f17e..364748a 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -242,6 +242,18 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
goto error;
}
+ if (append) {
+ int result;
+ Py_BEGIN_ALLOW_THREADS
+ errno = 0;
+ result = lseek(self->fd, 0, SEEK_END);
+ Py_END_ALLOW_THREADS
+ if (result < 0) {
+ close(self->fd);
+ PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
+ goto error;
+ }
+ }
}
goto done;