mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 23:24:41 +00:00
sdl 2.0.8 update
This commit is contained in:
parent
7f674a59c6
commit
bfb08f9482
894 changed files with 66879 additions and 43299 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -18,14 +18,27 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/* We won't get fseeko64 on QNX if _LARGEFILE64_SOURCE is defined, but the
|
||||
configure script knows the C runtime has it and enables it. */
|
||||
#ifndef __QNXNTO__
|
||||
/* Need this so Linux systems define fseek64o, ftell64o and off64_t */
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
/* This file provides a general interface for SDL to read and write
|
||||
data sources. It can easily be extended to files, memory, etc.
|
||||
|
|
@ -292,6 +305,42 @@ windows_file_close(SDL_RWops * context)
|
|||
|
||||
#ifdef HAVE_STDIO_H
|
||||
|
||||
#ifdef HAVE_FOPEN64
|
||||
#define fopen fopen64
|
||||
#endif
|
||||
#ifdef HAVE_FSEEKO64
|
||||
#define fseek_off_t off64_t
|
||||
#define fseek fseeko64
|
||||
#define ftell ftello64
|
||||
#elif defined(HAVE_FSEEKO)
|
||||
#if defined(OFF_MIN) && defined(OFF_MAX)
|
||||
#define FSEEK_OFF_MIN OFF_MIN
|
||||
#define FSEEK_OFF_MAX OFF_MAX
|
||||
#elif defined(HAVE_LIMITS_H)
|
||||
/* POSIX doesn't specify the minimum and maximum macros for off_t so
|
||||
* we have to improvise and dance around implementation-defined
|
||||
* behavior. This may fail if the off_t type has padding bits or
|
||||
* is not a two's-complement representation. The compilers will detect
|
||||
* and eliminate the dead code if off_t has 64 bits.
|
||||
*/
|
||||
#define FSEEK_OFF_MAX (((((off_t)1 << (sizeof(off_t) * CHAR_BIT - 2)) - 1) << 1) + 1)
|
||||
#define FSEEK_OFF_MIN (-(FSEEK_OFF_MAX) - 1)
|
||||
#endif
|
||||
#define fseek_off_t off_t
|
||||
#define fseek fseeko
|
||||
#define ftell ftello
|
||||
#elif defined(HAVE__FSEEKI64)
|
||||
#define fseek_off_t __int64
|
||||
#define fseek _fseeki64
|
||||
#define ftell _ftelli64
|
||||
#else
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#define FSEEK_OFF_MIN LONG_MIN
|
||||
#define FSEEK_OFF_MAX LONG_MAX
|
||||
#endif
|
||||
#define fseek_off_t long
|
||||
#endif
|
||||
|
||||
/* Functions to read/write stdio file pointers */
|
||||
|
||||
static Sint64 SDLCALL
|
||||
|
|
@ -312,23 +361,19 @@ stdio_size(SDL_RWops * context)
|
|||
static Sint64 SDLCALL
|
||||
stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
|
||||
{
|
||||
#ifdef HAVE_FSEEKO64
|
||||
if (fseeko64(context->hidden.stdio.fp, (off64_t)offset, whence) == 0) {
|
||||
return ftello64(context->hidden.stdio.fp);
|
||||
}
|
||||
#elif defined(HAVE_FSEEKO)
|
||||
if (fseeko(context->hidden.stdio.fp, (off_t)offset, whence) == 0) {
|
||||
return ftello(context->hidden.stdio.fp);
|
||||
}
|
||||
#elif defined(HAVE__FSEEKI64)
|
||||
if (_fseeki64(context->hidden.stdio.fp, offset, whence) == 0) {
|
||||
return _ftelli64(context->hidden.stdio.fp);
|
||||
}
|
||||
#else
|
||||
if (fseek(context->hidden.stdio.fp, offset, whence) == 0) {
|
||||
return ftell(context->hidden.stdio.fp);
|
||||
#if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
|
||||
if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) {
|
||||
return SDL_SetError("Seek offset out of range");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) {
|
||||
Sint64 pos = ftell(context->hidden.stdio.fp);
|
||||
if (pos < 0) {
|
||||
return SDL_SetError("Couldn't get stream offset");
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
return SDL_Error(SDL_EFSEEK);
|
||||
}
|
||||
|
||||
|
|
@ -653,6 +698,59 @@ SDL_FreeRW(SDL_RWops * area)
|
|||
SDL_free(area);
|
||||
}
|
||||
|
||||
/* Load all the data from an SDL data stream */
|
||||
void *
|
||||
SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
|
||||
{
|
||||
const int FILE_CHUNK_SIZE = 1024;
|
||||
Sint64 size;
|
||||
size_t size_read, size_total;
|
||||
void *data = NULL, *newdata;
|
||||
|
||||
if (!src) {
|
||||
SDL_InvalidParamError("src");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = SDL_RWsize(src);
|
||||
if (size < 0) {
|
||||
size = FILE_CHUNK_SIZE;
|
||||
}
|
||||
data = SDL_malloc((size_t)(size + 1));
|
||||
|
||||
size_total = 0;
|
||||
for (;;) {
|
||||
if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) {
|
||||
size = (size_total + FILE_CHUNK_SIZE);
|
||||
newdata = SDL_realloc(data, (size_t)(size + 1));
|
||||
if (!newdata) {
|
||||
SDL_free(data);
|
||||
data = NULL;
|
||||
SDL_OutOfMemory();
|
||||
goto done;
|
||||
}
|
||||
data = newdata;
|
||||
}
|
||||
|
||||
size_read = SDL_RWread(src, (char *)data+size_total, 1, (size_t)(size-size_total));
|
||||
if (size_read == 0) {
|
||||
break;
|
||||
}
|
||||
size_total += size_read;
|
||||
}
|
||||
|
||||
if (datasize) {
|
||||
*datasize = size_total;
|
||||
}
|
||||
((char *)data)[size_total] = '\0';
|
||||
|
||||
done:
|
||||
if (freesrc && src) {
|
||||
SDL_RWclose(src);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Functions for dynamically reading and writing endian-specific values */
|
||||
|
||||
Uint8
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue