2012-06-01 15:23:19 +00:00
|
|
|
// VFSInternal.h - misc things that are not required to be visible outside of the library.
|
|
|
|
// For conditions of distribution and use, see copyright notice in VFS.h
|
|
|
|
|
|
|
|
// !! this file is supposed to be included ONLY from VFS*.cpp files.
|
|
|
|
|
|
|
|
#ifndef VFS_INTERNAL_H
|
|
|
|
#define VFS_INTERNAL_H
|
|
|
|
|
|
|
|
// checks to enforce correct including
|
|
|
|
#ifdef TTVFS_VFS_H
|
2014-04-06 17:19:33 +00:00
|
|
|
#error Oops, TTVFS_VFS_H is defined, someone messed up and included ttvfs.h wrongly.
|
2012-06-01 15:23:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "VFSDefines.h"
|
|
|
|
|
2014-04-07 02:16:15 +00:00
|
|
|
#if defined(VFS_LARGEFILE_SUPPORT)
|
2014-04-07 03:09:40 +00:00
|
|
|
# ifndef _LARGEFILE_SOURCE
|
2014-04-07 02:16:15 +00:00
|
|
|
# define _LARGEFILE_SOURCE
|
2014-04-07 03:09:40 +00:00
|
|
|
# endif
|
|
|
|
# ifndef _LARGEFILE64_SOURCE
|
2014-04-07 02:16:15 +00:00
|
|
|
# define _LARGEFILE64_SOURCE
|
2014-04-07 03:09:40 +00:00
|
|
|
# endif
|
|
|
|
# ifdef _FILE_OFFSET_BITS
|
|
|
|
# undef _FILE_OFFSET_BITS
|
|
|
|
# endif
|
|
|
|
# ifndef _FILE_OFFSET_BITS
|
2014-04-07 02:16:15 +00:00
|
|
|
# define _FILE_OFFSET_BITS 64
|
2014-04-07 03:09:40 +00:00
|
|
|
# endif
|
2014-04-07 02:16:15 +00:00
|
|
|
#endif
|
2012-06-01 15:23:19 +00:00
|
|
|
|
|
|
|
#if _MSC_VER
|
|
|
|
# ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
# define _CRT_SECURE_NO_WARNINGS
|
|
|
|
# endif
|
2014-04-07 02:16:15 +00:00
|
|
|
# ifndef _CRT_SECURE_NO_DEPRECATE
|
2012-06-01 15:23:19 +00:00
|
|
|
# define _CRT_SECURE_NO_DEPRECATE
|
2014-04-07 02:16:15 +00:00
|
|
|
# endif
|
2012-06-01 15:23:19 +00:00
|
|
|
#endif
|
2014-04-07 02:16:15 +00:00
|
|
|
|
|
|
|
// 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
|
2012-06-01 15:23:19 +00:00
|
|
|
#endif
|
2014-04-07 02:16:15 +00:00
|
|
|
#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
|
2012-06-01 15:23:19 +00:00
|
|
|
|
2014-04-06 17:19:33 +00:00
|
|
|
template <typename DST, typename SRC> inline DST safecast(SRC p)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
assert(!p || static_cast<DST>(p) == dynamic_cast<DST>(p));
|
|
|
|
#endif
|
|
|
|
return static_cast<DST>(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename DST, typename SRC> inline DST safecastNonNull(SRC p)
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
assert(p && static_cast<DST>(p) == dynamic_cast<DST>(p));
|
|
|
|
#endif
|
|
|
|
return static_cast<DST>(p);
|
|
|
|
}
|
|
|
|
|
2014-04-07 02:16:15 +00:00
|
|
|
VFS_NAMESPACE_END
|
2012-06-01 15:23:19 +00:00
|
|
|
|
|
|
|
#endif
|