diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-21 00:56:37 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-21 00:56:37 (GMT) |
| commit | 19fec8b58fe46de77c7d12c91fe198584da5d0c8 (patch) | |
| tree | cb81650e38c1b513b5db4139c58239cb2c613460 /Modules/_fileio.c | |
| parent | 592f5fcb8d1d6f8c495e32ce0eae848c0e866dcd (diff) | |
| download | cpython-19fec8b58fe46de77c7d12c91fe198584da5d0c8.zip cpython-19fec8b58fe46de77c7d12c91fe198584da5d0c8.tar.gz cpython-19fec8b58fe46de77c7d12c91fe198584da5d0c8.tar.bz2 | |
Merged revisions 68835 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68835 | antoine.pitrou | 2009-01-21 01:45:36 +0100 (mer., 21 janv. 2009) | 6 lines
Issue #5008: When a file is opened in append mode with the new IO library,
do an explicit seek to the end of file (so that e.g. tell() returns the
file size rather than 0). This is consistent with the behaviour of the
traditional 2.x file object.
........
Diffstat (limited to 'Modules/_fileio.c')
| -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 0f09ecd..fbe4189 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -41,6 +41,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, errno (which is < 0) on failure. */ static int internal_close(PyFileIOObject *self) @@ -296,6 +299,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: |
