Index: Modules/_fileio.c =================================================================== --- Modules/_fileio.c (révision 68832) +++ Modules/_fileio.c (copie de travail) @@ -27,6 +27,12 @@ #include #endif +#if defined(MS_WIN64) || defined(MS_WINDOWS) +typedef PY_LONG_LONG Py_off_t; +#else +typedef off_t Py_off_t; +#endif + #if BUFSIZ < (8*1024) #define SMALLCHUNK (8*1024) #elif (BUFSIZ >= (2 << 25)) @@ -315,6 +321,17 @@ goto error; } + if (append) { + Py_off_t pos; + Py_BEGIN_ALLOW_THREADS + pos = lseek(self->fd, 0, SEEK_END); + Py_END_ALLOW_THREADS + if (pos < 0) { + PyErr_SetFromErrno(PyExc_IOError); + goto error; + } + } + goto done; error: @@ -570,12 +587,6 @@ /* XXX Windows support below is likely incomplete */ -#if defined(MS_WIN64) || defined(MS_WINDOWS) -typedef PY_LONG_LONG Py_off_t; -#else -typedef off_t Py_off_t; -#endif - /* Cribbed from posix_lseek() */ static PyObject * portable_lseek(int fd, PyObject *posobj, int whence) Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (révision 68832) +++ Lib/test/test_io.py (copie de travail) @@ -233,6 +233,17 @@ else: self.fail("1/0 didn't raise an exception") + # issue 5008 + def test_append(self): + with open(support.TESTFN, "wb") as f: + f.write(b"xxx") + with open(support.TESTFN, "ab") as f: + self.assertEqual(f.tell(), 3) + with open(support.TESTFN, "ab", buffering=0) as f: + self.assertEqual(f.tell(), 3) + with open(support.TESTFN, "a") as f: + self.assert_(f.tell() > 0) + def test_destructor(self): record = [] class MyFileIO(io.FileIO):