From 3d0ac9226701145b4e53559621987a799120baa8 Mon Sep 17 00:00:00 2001 From: truelight Date: Thu, 13 Sep 2007 18:46:29 +0000 Subject: (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind --- src/fileio.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/fileio.cpp') diff --git a/src/fileio.cpp b/src/fileio.cpp index ad278e15f..2d1c01c71 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -267,7 +267,7 @@ char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir) return buf; } -FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir) +FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize) { #if defined(WIN32) && defined(UNICODE) /* fopen is implemented as a define with ellipses for @@ -293,11 +293,17 @@ FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subd f = fopen(buf, mode); } #endif + if (f != NULL && filesize != NULL) { + /* Find the size of the file */ + fseek(f, 0, SEEK_END); + *filesize = ftell(f); + fseek(f, 0, SEEK_SET); + } return f; } /** Opens OpenTTD files somewhere in a personal or global directory */ -FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir) +FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *size) { FILE *f = NULL; Searchpath sp; @@ -305,7 +311,7 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir) assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY); FOR_ALL_SEARCHPATHS(sp) { - f = FioFOpenFileSp(filename, mode, sp, subdir); + f = FioFOpenFileSp(filename, mode, sp, subdir, size); if (f != NULL || subdir == NO_DIRECTORY) break; } -- cgit v1.2.3-54-g00ecf