If append mode is specified seek to the end of the file.
Add a test to test_fileio.py for this.
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 @@
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;