summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-11-23 13:15:07 +0000
committerrubidium <rubidium@openttd.org>2013-11-23 13:15:07 +0000
commit0e9c9921040a1d0e2aa4b820b20535f40a0d75a3 (patch)
tree6dd17568acbfb75610e9b4e248436426ead79e89 /src/fileio.cpp
parentb3e93d65208f74802595b12e682d98a4d534a328 (diff)
downloadopenttd-0e9c9921040a1d0e2aa4b820b20535f40a0d75a3.tar.xz
(svn r26058) -Fix: handle the return value of a number of functions better
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r--src/fileio.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 634033747..e17eaf654 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -88,7 +88,9 @@ void FioSeekTo(size_t pos, int mode)
if (mode == SEEK_CUR) pos += FioGetPos();
_fio.buffer = _fio.buffer_end = _fio.buffer_start + FIO_BUFFER_SIZE;
_fio.pos = pos;
- fseek(_fio.cur_fh, _fio.pos, SEEK_SET);
+ if (fseek(_fio.cur_fh, _fio.pos, SEEK_SET) < 0) {
+ DEBUG(misc, 0, "Seeking in %s failed", _fio.filename);
+ }
}
#if defined(LIMITED_FDS)
@@ -450,7 +452,11 @@ FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
FILE *f = fopen(entry->tar_filename, "rb");
if (f == NULL) return f;
- fseek(f, entry->position, SEEK_SET);
+ if (fseek(f, entry->position, SEEK_SET) < 0) {
+ fclose(f);
+ return NULL;
+ }
+
if (filesize != NULL) *filesize = entry->size;
return f;
}
@@ -533,6 +539,8 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
*/
static void FioCreateDirectory(const char *name)
{
+ /* Ignore directory creation errors; they'll surface later on, and most
+ * of the time they are 'directory already exists' errors anyhow. */
#if defined(WIN32) || defined(WINCE)
CreateDirectory(OTTD2FS(name), NULL);
#elif defined(OS2) && !defined(__INNOTEK_LIBC__)
@@ -897,7 +905,11 @@ bool TarScanner::AddFile(const char *filename, size_t basepath_length, const cha
/* Skip to the next block.. */
skip = Align(skip, 512);
- fseek(f, skip, SEEK_CUR);
+ if (fseek(f, skip, SEEK_CUR) < 0) {
+ DEBUG(misc, 0, "The file '%s' can't be read as a valid tar-file", filename);
+ fclose(f);
+ return false;
+ }
pos += skip;
}