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
|
#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 --- */
|
/* --- End of config section --- */
|
||||||
|
|
||||||
|
|
||||||
#define VFS_NAMESPACE_START namespace ttvfs {
|
#define VFS_NAMESPACE_START namespace ttvfs {
|
||||||
#define VFS_NAMESPACE_END }
|
#define VFS_NAMESPACE_END }
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER)
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
VFS_NAMESPACE_START
|
VFS_NAMESPACE_START
|
||||||
|
|
||||||
#ifdef VFS_LARGEFILE_SUPPORT
|
#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 */)
|
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;
|
return it != _subdirs.end() ? it->second : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
// For conditions of distribution and use, see copyright notice in VFS.h
|
// For conditions of distribution and use, see copyright notice in VFS.h
|
||||||
|
|
||||||
#include "VFSInternal.h"
|
#include "VFSInternal.h"
|
||||||
|
#include <stdio.h> // for SEEK_* constants
|
||||||
|
|
||||||
#include "VFSFile.h"
|
#include "VFSFile.h"
|
||||||
#include "VFSTools.h"
|
#include "VFSTools.h"
|
||||||
#include "VFSFileFuncs.h"
|
#include "VFSFileFuncs.h"
|
||||||
|
|
||||||
#include <cstdio> // for SEEK_* constants
|
|
||||||
|
|
||||||
VFS_NAMESPACE_START
|
VFS_NAMESPACE_START
|
||||||
|
|
||||||
|
@ -74,12 +75,12 @@ vfspos DiskFile::getpos() const
|
||||||
return _fh ? real_ftell((FILE*)_fh) : npos;
|
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;
|
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;
|
return _fh ? real_fwrite(src, 1, bytes, (FILE*)_fh) : 0;
|
||||||
}
|
}
|
||||||
|
@ -150,21 +151,21 @@ bool MemFile::seek(vfspos pos, int whence)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int MemFile::read(void *dst, unsigned int bytes)
|
size_t MemFile::read(void *dst, size_t bytes)
|
||||||
{
|
{
|
||||||
if(iseof())
|
if(iseof())
|
||||||
return 0;
|
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);
|
memcpy(dst, (char*)_buf + _pos, rem);
|
||||||
return 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())
|
if(iseof())
|
||||||
return 0;
|
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);
|
memcpy((char*)_buf + _pos, src, rem);
|
||||||
return 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"
|
#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 "VFSInternal.h"
|
||||||
|
#include "VFSFileFuncs.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
|
|
||||||
|
|
||||||
VFS_NAMESPACE_START
|
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)
|
void *real_fopen(const char *name, const char *mode)
|
||||||
{
|
{
|
||||||
return fopen(name, mode);
|
return fopen(name, mode);
|
||||||
|
|
|
@ -13,21 +13,41 @@
|
||||||
|
|
||||||
#include "VFSDefines.h"
|
#include "VFSDefines.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#if defined(VFS_LARGEFILE_SUPPORT)
|
||||||
#include <cstring>
|
# define _LARGEFILE_SOURCE
|
||||||
#include <string>
|
# define _LARGEFILE64_SOURCE
|
||||||
#include <cassert>
|
# define _FILE_OFFSET_BITS 64
|
||||||
|
#endif
|
||||||
|
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
# ifndef _CRT_SECURE_NO_WARNINGS
|
# ifndef _CRT_SECURE_NO_WARNINGS
|
||||||
# define _CRT_SECURE_NO_WARNINGS
|
# define _CRT_SECURE_NO_WARNINGS
|
||||||
# endif
|
# endif
|
||||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
# ifndef _CRT_SECURE_NO_DEPRECATE
|
||||||
# define _CRT_SECURE_NO_DEPRECATE
|
# define _CRT_SECURE_NO_DEPRECATE
|
||||||
|
# endif
|
||||||
#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
|
#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)
|
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);
|
return static_cast<DST>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VFS_NAMESPACE_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// VFSTools.cpp - useful functions and misc stuff
|
// VFSTools.cpp - useful functions and misc stuff
|
||||||
// For conditions of distribution and use, see copyright notice in VFS.h
|
// For conditions of distribution and use, see copyright notice in VFS.h
|
||||||
|
|
||||||
|
#include "VFSInternal.h"
|
||||||
#include "VFSTools.h"
|
#include "VFSTools.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
|
@ -273,19 +273,12 @@ bool CreateDirRec(const char *dir)
|
||||||
bool GetFileSize(const char* fn, vfspos& size)
|
bool GetFileSize(const char* fn, vfspos& size)
|
||||||
{
|
{
|
||||||
vfspos sz = 0;
|
vfspos sz = 0;
|
||||||
#ifdef VFS_LARGEFILE_SUPPORT
|
#if defined(VFS_LARGEFILE_SUPPORT) && defined(_MSC_VER)
|
||||||
# ifdef _MSC_VER
|
|
||||||
struct _stat64 st;
|
struct _stat64 st;
|
||||||
if(_stat64(fn, &st))
|
if(_stat64(fn, &st))
|
||||||
return false;
|
return false;
|
||||||
sz = st.st_size;
|
sz = st.st_size;
|
||||||
# else // _MSC_VER
|
#else
|
||||||
struct stat64 st;
|
|
||||||
if(stat64(fn, &st))
|
|
||||||
return false;
|
|
||||||
sz = st.st_size;
|
|
||||||
# endif
|
|
||||||
#else // VFS_LARGEFILE_SUPPORT
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(stat(fn, &st))
|
if(stat(fn, &st))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#ifndef VFS_TOOLS_H
|
#ifndef VFS_TOOLS_H
|
||||||
#define VFS_TOOLS_H
|
#define VFS_TOOLS_H
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <stdlib.h>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ bool InStream::open(const char *fn)
|
||||||
|
|
||||||
int ttvfs_stdio_fsize(VFILE *f, size_t *sizep)
|
int ttvfs_stdio_fsize(VFILE *f, size_t *sizep)
|
||||||
{
|
{
|
||||||
size_t sz = 0;
|
long int sz = 0;
|
||||||
if ( vfseek(f, 0, SEEK_END) != 0
|
if ( vfseek(f, 0, SEEK_END) != 0
|
||||||
|| (sz = vftell(f)) < 0
|
|| (sz = vftell(f)) < 0
|
||||||
|| vfseek(f, 0, SEEK_SET) != 0)
|
|| vfseek(f, 0, SEEK_SET) != 0)
|
||||||
|
|
|
@ -98,23 +98,20 @@ vfspos ZipFile::getpos() const
|
||||||
return _pos;
|
return _pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ZipFile::read(void *dst, unsigned int bytes)
|
size_t ZipFile::read(void *dst, size_t bytes)
|
||||||
{
|
{
|
||||||
if(!_buf && !unpack())
|
if(!_buf && !unpack())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
char *startptr = _buf + _pos;
|
char *startptr = _buf + _pos;
|
||||||
char *endptr = _buf + size();
|
char *endptr = _buf + size();
|
||||||
bytes = std::min((unsigned int)(endptr - startptr), bytes); // limit in case reading over buffer size
|
bytes = std::min<size_t>(endptr - startptr, bytes); // limit in case reading over buffer size
|
||||||
//if(_mode.find('b') == std::string::npos)
|
memcpy(dst, startptr, bytes); // binary copy
|
||||||
// strnNLcpy((char*)dst, (const char*)startptr, bytes); // non-binary == text mode
|
|
||||||
//else
|
|
||||||
memcpy(dst, startptr, bytes); // binary copy
|
|
||||||
_pos += bytes;
|
_pos += bytes;
|
||||||
return 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.
|
// TODO: implement actually writing to the underlying Zip file.
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ public:
|
||||||
virtual bool seek(vfspos pos, int whence);
|
virtual bool seek(vfspos pos, int whence);
|
||||||
virtual bool flush();
|
virtual bool flush();
|
||||||
virtual vfspos getpos() const;
|
virtual vfspos getpos() const;
|
||||||
virtual unsigned int read(void *dst, unsigned int bytes);
|
virtual size_t read(void *dst, size_t bytes);
|
||||||
virtual unsigned int write(const void *src, unsigned int bytes);
|
virtual size_t write(const void *src, size_t bytes);
|
||||||
virtual vfspos size();
|
virtual vfspos size();
|
||||||
virtual const char *getType() const { return "ZipFile"; }
|
virtual const char *getType() const { return "ZipFile"; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue