]> granicus.if.org Git - python/commitdiff
Check for fd of -1 to save fsync() and fstat() call
authorAndrew M. Kuchling <amk@amk.ca>
Thu, 10 Jan 2008 13:37:12 +0000 (13:37 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Thu, 10 Jan 2008 13:37:12 +0000 (13:37 +0000)
Modules/mmapmodule.c

index 2d745c130d559dd61aa56d6ea2822d2991b476c5..9a39b2424e8e1c694962af6fa5b509fd2ea686b3 100644 (file)
@@ -1059,9 +1059,11 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
 #ifdef HAVE_FSTAT
 #  ifdef __VMS
        /* on OpenVMS we must ensure that all bytes are written to the file */
-       fsync(fd);
+       if (fd != -1) {
+               fsync(fd);
+       }
 #  endif
-       if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
+       if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
                if (map_size == 0) {
                        map_size = st.st_size;
                } else if ((size_t)offset + (size_t)map_size > st.st_size) {