diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2008-01-10 13:37:12 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2008-01-10 13:37:12 (GMT) |
commit | 7c22ccc3dd9a51cfdbd0ac0df830ba9e622bcf80 (patch) | |
tree | 08a81f917fff2b23f5fbdc90106b514bea962580 /Modules | |
parent | 3fc15b8ba49ffcbda6da78b8ca2b67b358df61f2 (diff) | |
download | cpython-7c22ccc3dd9a51cfdbd0ac0df830ba9e622bcf80.zip cpython-7c22ccc3dd9a51cfdbd0ac0df830ba9e622bcf80.tar.gz cpython-7c22ccc3dd9a51cfdbd0ac0df830ba9e622bcf80.tar.bz2 |
Check for fd of -1 to save fsync() and fstat() call
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/mmapmodule.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 2d745c1..9a39b24 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) { |