# HG changeset patch # User darkvater # Date 1105879225 0 # Node ID 309068e65b16dc5fb55dc62ebb0b50d24c18ac04 # Parent fb62bb1c424fd293a15f50e8dfaa5b725acbac96 (svn r1540) -Fix: since grf files are reopened on every load/new game, close the old opened to fix stale filehandles (thx tamlin) diff -r fb62bb1c424f -r 309068e65b16 fileio.c --- a/fileio.c Sun Jan 16 12:30:52 2005 +0000 +++ b/fileio.c Sun Jan 16 12:40:25 2005 +0000 @@ -83,16 +83,20 @@ 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 @@ 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); }