Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e41148

Browse files
committed
Use O_APPEND flag instead of seeking, when append
mode is specified.
1 parent 5b1284d commit 0e41148

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

Modules/_fileio.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
230230
flags |= O_BINARY;
231231
#endif
232232

233+
#ifdef O_APPEND
234+
if (append)
235+
flags |= O_APPEND;
236+
#endif
237+
233238
if (fd >= 0) {
234239
self->fd = fd;
235240
}
@@ -242,18 +247,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
242247
PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
243248
goto error;
244249
}
245-
if (append) {
246-
int result;
247-
Py_BEGIN_ALLOW_THREADS
248-
errno = 0;
249-
result = lseek(self->fd, 0, SEEK_END);
250-
Py_END_ALLOW_THREADS
251-
if (result < 0) {
252-
close(self->fd);
253-
PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
254-
goto error;
255-
}
256-
}
257250
}
258251

259252
goto done;

0 commit comments

Comments
 (0)