From f987f5f119dac02d3863e47e3eecc0e656536bd3 Mon Sep 17 00:00:00 2001 From: darkvater Date: Sun, 16 Jan 2005 12:40:25 +0000 Subject: (svn r1540) -Fix: since grf files are reopened on every load/new game, close the old opened to fix stale filehandles (thx tamlin) --- fileio.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fileio.c b/fileio.c index bd5da1e6c..9baa5ed79 100644 --- a/fileio.c +++ b/fileio.c @@ -83,16 +83,20 @@ void FioReadBlock(void *ptr, uint size) fread(ptr, 1, size, _fio.cur_fh); } +static inline void FioCloseFile(int slot) +{ + if (_fio.handles[slot] != NULL) { + fclose(_fio.handles[slot]); + _fio.handles[slot] = NULL; + } +} + void FioCloseAll(void) { int i; - for (i = 0; i != lengthof(_fio.handles); i++) { - if (_fio.handles[i] != NULL) { - fclose(_fio.handles[i]); - _fio.handles[i] = NULL; - } - } + for (i = 0; i != lengthof(_fio.handles); i++) + FioCloseFile(i); } void FioOpenFile(int slot, const char *filename) @@ -126,6 +130,7 @@ void FioOpenFile(int slot, const char *filename) if (f == NULL) error("Cannot open file '%s'", buf); + FioCloseFile(slot); // if file was opened before, close it _fio.handles[slot] = f; FioSeekToFile(slot << 24); } -- cgit v1.2.3-70-g09d2