From: Andrew M. Kuchling Date: Thu, 10 Jan 2008 13:37:12 +0000 (+0000) Subject: Check for fd of -1 to save fsync() and fstat() call X-Git-Tag: v2.6a1~657 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c22ccc3dd9a51cfdbd0ac0df830ba9e622bcf80;p=python Check for fd of -1 to save fsync() and fstat() call --- diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 2d745c130d..9a39b2424e 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -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) {