diff --git a/ExternalLibs/ttvfs/VFSDefines.h b/ExternalLibs/ttvfs/VFSDefines.h index b5c0e41..d0cf3cc 100644 --- a/ExternalLibs/ttvfs/VFSDefines.h +++ b/ExternalLibs/ttvfs/VFSDefines.h @@ -21,24 +21,17 @@ #define VFS_IGNORE_CASE -// These are used for small, temporary memory allocations that can remain on the stack. -// If alloca is available, this is the preferred way. -#include -#ifdef _WIN32 -# include // MSVC/MinGW still need this for alloca. Seems to be windows-specific failure -#endif -#define VFS_STACK_ALLOC(size) alloca(size) -#define VFS_STACK_FREE(ptr) /* no need to free anything here */ -// Fail-safe: -//#define VFS_STACK_ALLOC(size) malloc(size) -//#define VFS_STACK_FREE(ptr) free(ptr) - /* --- End of config section --- */ #define VFS_NAMESPACE_START namespace ttvfs { #define VFS_NAMESPACE_END } + +#if !defined(_MSC_VER) +# include +#endif + VFS_NAMESPACE_START #ifdef VFS_LARGEFILE_SUPPORT diff --git a/ExternalLibs/ttvfs/VFSDir.cpp b/ExternalLibs/ttvfs/VFSDir.cpp index 211ced1..5d02839 100644 --- a/ExternalLibs/ttvfs/VFSDir.cpp +++ b/ExternalLibs/ttvfs/VFSDir.cpp @@ -138,7 +138,7 @@ void DirBase::forEachDir(DirEnumCallback f, void *user /* = NULL */, bool safe / DirBase *DirBase::getDirByName(const char *dn, bool /* unused: lazyLoad = true */, bool useSubtrees /* = true */) { - Dirs::const_iterator it = _subdirs.find(dn); + Dirs::iterator it = _subdirs.find(dn); return it != _subdirs.end() ? it->second : NULL; } diff --git a/ExternalLibs/ttvfs/VFSFile.cpp b/ExternalLibs/ttvfs/VFSFile.cpp index 431c40a..b5d2082 100644 --- a/ExternalLibs/ttvfs/VFSFile.cpp +++ b/ExternalLibs/ttvfs/VFSFile.cpp @@ -2,11 +2,12 @@ // For conditions of distribution and use, see copyright notice in VFS.h #include "VFSInternal.h" +#include // for SEEK_* constants + #include "VFSFile.h" #include "VFSTools.h" #include "VFSFileFuncs.h" -#include // for SEEK_* constants VFS_NAMESPACE_START @@ -74,12 +75,12 @@ vfspos DiskFile::getpos() const return _fh ? real_ftell((FILE*)_fh) : npos; } -unsigned int DiskFile::read(void *dst, size_t bytes) +size_t DiskFile::read(void *dst, size_t bytes) { return _fh ? real_fread(dst, 1, bytes, (FILE*)_fh) : 0; } -unsigned int DiskFile::write(const void *src, size_t bytes) +size_t DiskFile::write(const void *src, size_t bytes) { return _fh ? real_fwrite(src, 1, bytes, (FILE*)_fh) : 0; } @@ -150,21 +151,21 @@ bool MemFile::seek(vfspos pos, int whence) return false; } -unsigned int MemFile::read(void *dst, unsigned int bytes) +size_t MemFile::read(void *dst, size_t bytes) { if(iseof()) return 0; - unsigned int rem = std::min((unsigned int)(_size - _pos), bytes); + size_t rem = std::min((size_t)(_size - _pos), bytes); memcpy(dst, (char*)_buf + _pos, rem); return rem; } -unsigned int MemFile::write(const void *src, unsigned int bytes) +size_t MemFile::write(const void *src, size_t bytes) { if(iseof()) return 0; - unsigned int rem = std::min((unsigned int)(_size - _pos), bytes); + size_t rem = std::min((size_t)(_size - _pos), bytes); memcpy((char*)_buf + _pos, src, rem); return rem; diff --git a/ExternalLibs/ttvfs/VFSFileFuncs.cpp b/ExternalLibs/ttvfs/VFSFileFuncs.cpp index 8543aa7..b6a749b 100644 --- a/ExternalLibs/ttvfs/VFSFileFuncs.cpp +++ b/ExternalLibs/ttvfs/VFSFileFuncs.cpp @@ -1,28 +1,21 @@ -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) -# define _CRT_SECURE_NO_WARNINGS -#endif - #include "VFSDefines.h" - -// this is for POSIX - define before including any stdio headers -#ifdef VFS_LARGEFILE_SUPPORT -# ifndef _MSC_VER -# define _FILE_OFFSET_BITS 64 -# endif -#endif - -#include "VFSFileFuncs.h" #include "VFSInternal.h" - -#include - -// Compile time assertion to make sure things work as expected -#if defined(VFS_LARGEFILE_SUPPORT) && !defined(_MSC_VER) -static void _dummy_() { switch(0) { case 4: case sizeof(off_t): ; } } -#endif +#include "VFSFileFuncs.h" VFS_NAMESPACE_START +// Compile time assertion to make sure things work as expected +#if defined(VFS_LARGEFILE_SUPPORT) +static void _dummy_() +{ + switch(0) { case 0:; case 4: case sizeof(vfspos): ; } +#ifndef _MSC_VER + switch(0) { case 0:; case 4: case sizeof(off_t): ; } +#endif +} +#endif + + void *real_fopen(const char *name, const char *mode) { return fopen(name, mode); diff --git a/ExternalLibs/ttvfs/VFSInternal.h b/ExternalLibs/ttvfs/VFSInternal.h index 37bd5a2..bcf8d78 100644 --- a/ExternalLibs/ttvfs/VFSInternal.h +++ b/ExternalLibs/ttvfs/VFSInternal.h @@ -13,21 +13,41 @@ #include "VFSDefines.h" -#include -#include -#include -#include - +#if defined(VFS_LARGEFILE_SUPPORT) +# define _LARGEFILE_SOURCE +# define _LARGEFILE64_SOURCE +# define _FILE_OFFSET_BITS 64 +#endif #if _MSC_VER # ifndef _CRT_SECURE_NO_WARNINGS # define _CRT_SECURE_NO_WARNINGS # endif -#ifndef _CRT_SECURE_NO_DEPRECATE +# ifndef _CRT_SECURE_NO_DEPRECATE # define _CRT_SECURE_NO_DEPRECATE +# endif #endif -# pragma warning(disable: 4355) // 'this' : used in base member initializer list + +// These are used for small, temporary memory allocations that can remain on the stack. +// If alloca is available, this is the preferred way. +#include +#ifdef _WIN32 +# include // MSVC/MinGW still need this for alloca. Seems to be windows-specific failure #endif +#define VFS_STACK_ALLOC(size) alloca(size) +#define VFS_STACK_FREE(ptr) /* no need to free anything here */ +// Fail-safe: +//#define VFS_STACK_ALLOC(size) malloc(size) +//#define VFS_STACK_FREE(ptr) free(ptr) + + +#include +#include +#include + + + +VFS_NAMESPACE_START template inline DST safecast(SRC p) { @@ -45,5 +65,6 @@ template inline DST safecastNonNull(SRC p) return static_cast(p); } +VFS_NAMESPACE_END #endif diff --git a/ExternalLibs/ttvfs/VFSTools.cpp b/ExternalLibs/ttvfs/VFSTools.cpp index a8f922d..f14022d 100644 --- a/ExternalLibs/ttvfs/VFSTools.cpp +++ b/ExternalLibs/ttvfs/VFSTools.cpp @@ -1,11 +1,11 @@ // VFSTools.cpp - useful functions and misc stuff // For conditions of distribution and use, see copyright notice in VFS.h +#include "VFSInternal.h" #include "VFSTools.h" #include -#include - +#include #if _WIN32 # define WIN32_LEAN_AND_MEAN @@ -273,19 +273,12 @@ bool CreateDirRec(const char *dir) bool GetFileSize(const char* fn, vfspos& size) { vfspos sz = 0; -#ifdef VFS_LARGEFILE_SUPPORT -# ifdef _MSC_VER +#if defined(VFS_LARGEFILE_SUPPORT) && defined(_MSC_VER) struct _stat64 st; if(_stat64(fn, &st)) return false; sz = st.st_size; -# else // _MSC_VER - struct stat64 st; - if(stat64(fn, &st)) - return false; - sz = st.st_size; -# endif -#else // VFS_LARGEFILE_SUPPORT +#else struct stat st; if(stat(fn, &st)) return false; diff --git a/ExternalLibs/ttvfs/VFSTools.h b/ExternalLibs/ttvfs/VFSTools.h index bbef7f8..2252ed5 100644 --- a/ExternalLibs/ttvfs/VFSTools.h +++ b/ExternalLibs/ttvfs/VFSTools.h @@ -7,7 +7,7 @@ #ifndef VFS_TOOLS_H #define VFS_TOOLS_H -#include +#include #include #include diff --git a/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.cpp b/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.cpp index f8a58ef..a719192 100644 --- a/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.cpp +++ b/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.cpp @@ -124,7 +124,7 @@ bool InStream::open(const char *fn) int ttvfs_stdio_fsize(VFILE *f, size_t *sizep) { - size_t sz = 0; + long int sz = 0; if ( vfseek(f, 0, SEEK_END) != 0 || (sz = vftell(f)) < 0 || vfseek(f, 0, SEEK_SET) != 0) diff --git a/ExternalLibs/ttvfs_zip/VFSFileZip.cpp b/ExternalLibs/ttvfs_zip/VFSFileZip.cpp index 7eb5b0b..bc76a47 100644 --- a/ExternalLibs/ttvfs_zip/VFSFileZip.cpp +++ b/ExternalLibs/ttvfs_zip/VFSFileZip.cpp @@ -98,23 +98,20 @@ vfspos ZipFile::getpos() const return _pos; } -unsigned int ZipFile::read(void *dst, unsigned int bytes) +size_t ZipFile::read(void *dst, size_t bytes) { if(!_buf && !unpack()) return 0; char *startptr = _buf + _pos; char *endptr = _buf + size(); - bytes = std::min((unsigned int)(endptr - startptr), bytes); // limit in case reading over buffer size - //if(_mode.find('b') == std::string::npos) - // strnNLcpy((char*)dst, (const char*)startptr, bytes); // non-binary == text mode - //else - memcpy(dst, startptr, bytes); // binary copy + bytes = std::min(endptr - startptr, bytes); // limit in case reading over buffer size + memcpy(dst, startptr, bytes); // binary copy _pos += bytes; return bytes; } -unsigned int ZipFile::write(const void *src, unsigned int bytes) +size_t ZipFile::write(const void *src, size_t bytes) { // TODO: implement actually writing to the underlying Zip file. diff --git a/ExternalLibs/ttvfs_zip/VFSFileZip.h b/ExternalLibs/ttvfs_zip/VFSFileZip.h index 108e65f..0ba0a22 100644 --- a/ExternalLibs/ttvfs_zip/VFSFileZip.h +++ b/ExternalLibs/ttvfs_zip/VFSFileZip.h @@ -18,8 +18,8 @@ public: virtual bool seek(vfspos pos, int whence); virtual bool flush(); virtual vfspos getpos() const; - virtual unsigned int read(void *dst, unsigned int bytes); - virtual unsigned int write(const void *src, unsigned int bytes); + virtual size_t read(void *dst, size_t bytes); + virtual size_t write(const void *src, size_t bytes); virtual vfspos size(); virtual const char *getType() const { return "ZipFile"; }