Only flush file handles on close if they were opened for writing. stable-3.0
authorRyan C. Gordon <icculus@icculus.org>
Mon, 18 Mar 2019 11:27:26 -0400
branchstable-3.0
changeset 1661 9959f9307e47
parent 1658 5ebf7cddf502
child 1662 c8f3bbd689d6
Only flush file handles on close if they were opened for writing. (transplanted from 89e1b79e10c6e9faf9e4c06dc357dee5ef2c7d4f)
src/physfs.c
--- a/src/physfs.c	Sun Feb 10 15:56:21 2019 -0500
+++ b/src/physfs.c	Mon Mar 18 11:27:26 2019 -0400
@@ -2678,12 +2678,15 @@
             PHYSFS_uint8 *tmp = handle->buffer;
 
             /* send our buffer to io... */
-            if (!PHYSFS_flush((PHYSFS_File *) handle))
-                return -1;
-
-            /* ...then have io send it to the disk... */
-            else if (io->flush && !io->flush(io))
-                return -1;
+            if (!handle->forReading)
+            {
+                if (!PHYSFS_flush((PHYSFS_File *) handle))
+                    return -1;
+
+                /* ...then have io send it to the disk... */
+                else if (io->flush && !io->flush(io))
+                    return -1;
+            } /* if */
 
             /* ...then close the underlying file. */
             io->destroy(io);