Don't fsync() read-only filehandles (thanks, Andreas!).
authorRyan C. Gordon <icculus@icculus.org>
Wed, 21 Aug 2013 23:30:33 -0400
changeset 1335 1b9a72908ece
parent 1334 8214ccf21d36
child 1337 3b2e649c044c
Don't fsync() read-only filehandles (thanks, Andreas!). This sounds harmless, but it actually forces a write of the inode's atime, which means a lot of painful and unnecessary disk i/o on some filesystems. Should be a good speedup on games that read a lot of small files on Unix.
docs/CREDITS.txt
src/platform_posix.c
--- a/docs/CREDITS.txt	Tue Aug 20 13:36:34 2013 -0400
+++ b/docs/CREDITS.txt	Wed Aug 21 23:30:33 2013 -0400
@@ -136,6 +136,9 @@
 Bug fixes:
     Dmitry Marakasov
 
+Bug fixes:
+    Andreas Karlsson
+
 Other stuff:
     Your name here! Patches go to icculus@icculus.org ...
 
--- a/src/platform_posix.c	Tue Aug 20 13:36:34 2013 -0400
+++ b/src/platform_posix.c	Wed Aug 21 23:30:33 2013 -0400
@@ -279,7 +279,8 @@
 int __PHYSFS_platformFlush(void *opaque)
 {
     const int fd = *((int *) opaque);
-    BAIL_IF_MACRO(fsync(fd) == -1, errcodeFromErrno(), 0);
+    if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY)
+        BAIL_IF_MACRO(fsync(fd) == -1, errcodeFromErrno(), 0);
     return 1;
 } /* __PHYSFS_platformFlush */