Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -92,7 +92,7 @@ static int SDLCALL windows_file_open(SDL_RWops *context, const char *filename, c
context->hidden.windowsio.buffer.data =
(char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.windowsio.buffer.data) {
return SDL_OutOfMemory();
return -1;
}
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) && !defined(__WINRT__)
/* Do not open a dialog box if failure */
@ -389,7 +389,7 @@ static SDL_RWops *SDL_RWFromFP(void *fp, SDL_bool autoclose)
SDL_RWops *rwops = NULL;
rwops = SDL_CreateRW();
if (rwops != NULL) {
if (rwops) {
rwops->seek = stdio_seek;
rwops->read = stdio_read;
rwops->write = stdio_write;
@ -462,7 +462,7 @@ static size_t SDLCALL mem_write(SDL_RWops *context, const void *ptr, size_t size
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
{
SDL_RWops *rwops = NULL;
if (file == NULL || !*file || mode == NULL || !*mode) {
if (!file || !*file || !mode || !*mode) {
SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
return NULL;
}
@ -495,7 +495,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
/* Try to open the file from the asset system */
rwops = SDL_CreateRW();
if (rwops == NULL) {
if (!rwops) {
return NULL; /* SDL_SetError already setup by SDL_CreateRW() */
}
@ -512,7 +512,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
#elif defined(__WIN32__) || defined(__GDK__) || defined(__WINRT__)
rwops = SDL_CreateRW();
if (rwops == NULL) {
if (!rwops) {
return NULL; /* SDL_SetError already setup by SDL_CreateRW() */
}
@ -538,7 +538,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
#else
FILE *fp = fopen(file, mode);
#endif
if (fp == NULL) {
if (!fp) {
SDL_SetError("Couldn't open %s", file);
} else {
rwops = SDL_RWFromFP(fp, SDL_TRUE);
@ -555,7 +555,7 @@ SDL_RWops *SDL_RWFromMem(void *mem, size_t size)
{
SDL_RWops *rwops = NULL;
if (mem == NULL) {
if (!mem) {
SDL_InvalidParamError("mem");
return NULL;
}
@ -565,7 +565,7 @@ SDL_RWops *SDL_RWFromMem(void *mem, size_t size)
}
rwops = SDL_CreateRW();
if (rwops != NULL) {
if (rwops) {
rwops->size = mem_size;
rwops->seek = mem_seek;
rwops->read = mem_read;
@ -582,7 +582,7 @@ SDL_RWops *SDL_RWFromConstMem(const void *mem, size_t size)
{
SDL_RWops *rwops = NULL;
if (mem == NULL) {
if (!mem) {
SDL_InvalidParamError("mem");
return NULL;
}
@ -592,7 +592,7 @@ SDL_RWops *SDL_RWFromConstMem(const void *mem, size_t size)
}
rwops = SDL_CreateRW();
if (rwops != NULL) {
if (rwops) {
rwops->size = mem_size;
rwops->seek = mem_seek;
rwops->read = mem_read;
@ -609,9 +609,7 @@ SDL_RWops *SDL_CreateRW(void)
SDL_RWops *context;
context = (SDL_RWops *)SDL_calloc(1, sizeof(*context));
if (context == NULL) {
SDL_OutOfMemory();
} else {
if (context) {
context->type = SDL_RWOPS_UNKNOWN;
}
return context;
@ -619,6 +617,7 @@ SDL_RWops *SDL_CreateRW(void)
void SDL_DestroyRW(SDL_RWops *context)
{
SDL_DestroyProperties(context->props);
SDL_free(context);
}
@ -631,7 +630,7 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
char *data = NULL, *newdata;
SDL_bool loading_chunks = SDL_FALSE;
if (src == NULL) {
if (!src) {
SDL_InvalidParamError("src");
return NULL;
}
@ -642,12 +641,10 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
loading_chunks = SDL_TRUE;
}
if (size >= SDL_SIZE_MAX) {
SDL_OutOfMemory();
goto done;
}
data = (char *)SDL_malloc((size_t)(size + 1));
if (!data) {
SDL_OutOfMemory();
goto done;
}
@ -661,10 +658,9 @@ void *SDL_LoadFile_RW(SDL_RWops *src, size_t *datasize, SDL_bool freesrc)
} else {
newdata = SDL_realloc(data, (size_t)(size + 1));
}
if (newdata == NULL) {
if (!newdata) {
SDL_free(data);
data = NULL;
SDL_OutOfMemory();
goto done;
}
data = newdata;
@ -698,6 +694,19 @@ void *SDL_LoadFile(const char *file, size_t *datasize)
return SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, SDL_TRUE);
}
SDL_PropertiesID SDL_GetRWProperties(SDL_RWops *context)
{
if (!context) {
SDL_InvalidParamError("context");
return 0;
}
if (context->props == 0) {
context->props = SDL_CreateProperties();
}
return context->props;
}
Sint64 SDL_RWsize(SDL_RWops *context)
{
if (!context) {
@ -794,6 +803,41 @@ size_t SDL_RWwrite(SDL_RWops *context, const void *ptr, size_t size)
return bytes;
}
size_t SDL_RWprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int size;
char *string;
size_t bytes;
va_start(ap, fmt);
size = SDL_vasprintf(&string, fmt, ap);
va_end(ap);
if (size < 0) {
return 0;
}
bytes = SDL_RWwrite(context, string, (size_t)size);
SDL_free(string);
return bytes;
}
size_t SDL_RWvprintf(SDL_RWops *context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
{
int size;
char *string;
size_t bytes;
size = SDL_vasprintf(&string, fmt, ap);
if (size < 0) {
return 0;
}
bytes = SDL_RWwrite(context, string, (size_t)size);
SDL_free(string);
return bytes;
}
int SDL_RWclose(SDL_RWops *context)
{
if (!context) {
@ -938,13 +982,13 @@ SDL_bool SDL_ReadS64BE(SDL_RWops *src, Sint64 *value)
SDL_bool SDL_WriteU8(SDL_RWops *dst, Uint8 value)
{
return (SDL_RWwrite(dst, &value, sizeof(value)) == sizeof(value)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &value, sizeof(value)) == sizeof(value));
}
SDL_bool SDL_WriteU16LE(SDL_RWops *dst, Uint16 value)
{
const Uint16 swapped = SDL_SwapLE16(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS16LE(SDL_RWops *dst, Sint16 value)
@ -955,7 +999,7 @@ SDL_bool SDL_WriteS16LE(SDL_RWops *dst, Sint16 value)
SDL_bool SDL_WriteU16BE(SDL_RWops *dst, Uint16 value)
{
const Uint16 swapped = SDL_SwapBE16(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS16BE(SDL_RWops *dst, Sint16 value)
@ -966,7 +1010,7 @@ SDL_bool SDL_WriteS16BE(SDL_RWops *dst, Sint16 value)
SDL_bool SDL_WriteU32LE(SDL_RWops *dst, Uint32 value)
{
const Uint32 swapped = SDL_SwapLE32(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS32LE(SDL_RWops *dst, Sint32 value)
@ -977,7 +1021,7 @@ SDL_bool SDL_WriteS32LE(SDL_RWops *dst, Sint32 value)
SDL_bool SDL_WriteU32BE(SDL_RWops *dst, Uint32 value)
{
const Uint32 swapped = SDL_SwapBE32(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS32BE(SDL_RWops *dst, Sint32 value)
@ -988,7 +1032,7 @@ SDL_bool SDL_WriteS32BE(SDL_RWops *dst, Sint32 value)
SDL_bool SDL_WriteU64LE(SDL_RWops *dst, Uint64 value)
{
const Uint64 swapped = SDL_SwapLE64(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS64LE(SDL_RWops *dst, Sint64 value)
@ -999,7 +1043,7 @@ SDL_bool SDL_WriteS64LE(SDL_RWops *dst, Sint64 value)
SDL_bool SDL_WriteU64BE(SDL_RWops *dst, Uint64 value)
{
const Uint64 swapped = SDL_SwapBE64(value);
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped)) ? SDL_TRUE : SDL_FALSE;
return (SDL_RWwrite(dst, &swapped, sizeof(swapped)) == sizeof(swapped));
}
SDL_bool SDL_WriteS64BE(SDL_RWops *dst, Sint64 value)

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -65,7 +65,7 @@ static FILE *TryOpenFile(const char *file, const char *mode)
FILE *fp = NULL;
fp = TryOpenInRomfs(file, mode);
if (fp == NULL) {
if (!fp) {
fp = fopen(file, mode);
}
@ -78,7 +78,6 @@ FILE *TryOpenInRomfs(const char *file, const char *mode)
char *prefixed_filepath = NULL;
if (SDL_asprintf(&prefixed_filepath, "romfs:/%s", file) < 0) {
SDL_OutOfMemory();
return NULL;
}

View File

@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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