Only flush file handles on close if they were opened for writing.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 18 Mar 2019 11:27:26 -0400
changeset 1660 89e1b79e10c6
parent 1659 44a00c6361b0
child 1663 7564353d225f
Only flush file handles on close if they were opened for writing.
src/physfs.c
--- a/src/physfs.c	Sun Feb 10 16:00:39 2019 -0500
+++ b/src/physfs.c	Mon Mar 18 11:27:26 2019 -0400
@@ -2760,12 +2760,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);