mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 06:24:32 +00:00
sync with ttvfs repo
This commit is contained in:
parent
b437a7cb2c
commit
0bf247169a
10 changed files with 67 additions and 69 deletions
|
@ -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 <cstdlib>
|
||||
#ifdef _WIN32
|
||||
# include <malloc.h> // 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 <stdint.h>
|
||||
#endif
|
||||
|
||||
VFS_NAMESPACE_START
|
||||
|
||||
#ifdef VFS_LARGEFILE_SUPPORT
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
// For conditions of distribution and use, see copyright notice in VFS.h
|
||||
|
||||
#include "VFSInternal.h"
|
||||
#include <stdio.h> // for SEEK_* constants
|
||||
|
||||
#include "VFSFile.h"
|
||||
#include "VFSTools.h"
|
||||
#include "VFSFileFuncs.h"
|
||||
|
||||
#include <cstdio> // 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>((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>((unsigned int)(_size - _pos), bytes);
|
||||
size_t rem = std::min((size_t)(_size - _pos), bytes);
|
||||
|
||||
memcpy((char*)_buf + _pos, src, rem);
|
||||
return rem;
|
||||
|
|
|
@ -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 <cstdio>
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -13,21 +13,41 @@
|
|||
|
||||
#include "VFSDefines.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#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 <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
# include <malloc.h> // 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 <string.h>
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
|
||||
VFS_NAMESPACE_START
|
||||
|
||||
template <typename DST, typename SRC> inline DST safecast(SRC p)
|
||||
{
|
||||
|
@ -45,5 +65,6 @@ template <typename DST, typename SRC> inline DST safecastNonNull(SRC p)
|
|||
return static_cast<DST>(p);
|
||||
}
|
||||
|
||||
VFS_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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 <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef VFS_TOOLS_H
|
||||
#define VFS_TOOLS_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdlib.h>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
bytes = std::min<size_t>(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.
|
||||
|
||||
|
|
|
@ -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"; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue