]> granicus.if.org Git - python/commitdiff
Use O_APPEND flag instead of seeking, when append
authorWalter Dörwald <walter@livinglogic.de>
Wed, 6 Jun 2007 16:55:38 +0000 (16:55 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 6 Jun 2007 16:55:38 +0000 (16:55 +0000)
mode is specified.

Modules/_fileio.c

index 364748adee6566e893023604a105045760afb284..660402f0c76e8baa12175a48b1b0b9d0bd79afd8 100644 (file)
@@ -230,6 +230,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
        flags |= O_BINARY;
 #endif
 
+#ifdef O_APPEND
+       if (append)
+               flags |= O_APPEND;
+#endif
+
        if (fd >= 0) {
                self->fd = fd;
        }
@@ -242,18 +247,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
                        PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
                        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;