diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_fileio.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c index 5b840c0..7a71837 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -55,6 +55,9 @@ PyTypeObject PyFileIO_Type; #define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type)) +static PyObject * +portable_lseek(int fd, PyObject *posobj, int whence); + /* Returns 0 on success, -1 with exception set on failure. */ static int internal_close(PyFileIOObject *self) @@ -315,6 +318,16 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) goto error; } + if (append) { + /* For consistent behaviour, we explicitly seek to the + end of file (otherwise, it might be done only on the + first write()). */ + PyObject *pos = portable_lseek(self->fd, NULL, 2); + if (pos == NULL) + goto error; + Py_DECREF(pos); + } + goto done; error: |