mirror of
https://github.com/python/cpython.git
synced 2025-12-03 16:19:41 +00:00
Use O_APPEND flag instead of seeking, when append
mode is specified.
This commit is contained in:
parent
5b1284d0b7
commit
0e41148c4b
1 changed files with 5 additions and 12 deletions
|
|
@ -230,6 +230,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
flags |= O_BINARY;
|
flags |= O_BINARY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef O_APPEND
|
||||||
|
if (append)
|
||||||
|
flags |= O_APPEND;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
self->fd = fd;
|
self->fd = fd;
|
||||||
}
|
}
|
||||||
|
|
@ -242,18 +247,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
|
||||||
PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
|
PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
|
||||||
goto error;
|
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;
|
goto done;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue