diff options
author | darkvater <darkvater@openttd.org> | 2005-01-16 12:40:25 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2005-01-16 12:40:25 +0000 |
commit | 340a9ab6becbfe31f410aed4de4c5bbc2a2658e5 (patch) | |
tree | 8932fdc484e531a560f35ac1395b29429eec18e8 | |
parent | 8efc7866dd577091b4cde55cecf03c1af5c9c22a (diff) | |
download | openttd-340a9ab6becbfe31f410aed4de4c5bbc2a2658e5.tar.xz |
(svn r1540) -Fix: since grf files are reopened on every load/new game, close the old opened to fix stale filehandles (thx tamlin)
-rw-r--r-- | fileio.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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); } |