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
@@ -27,12 +27,12 @@
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
/* Ignore call if invalid format pointer was passed */
if (fmt != NULL) {
if (fmt) {
va_list ap;
int result;
SDL_error *error = SDL_GetErrBuf();
SDL_error *error = SDL_GetErrBuf(SDL_TRUE);
error->error = 1; /* mark error as valid */
error->error = SDL_ErrorCodeGeneric;
va_start(ap, fmt);
result = SDL_vsnprintf(error->str, error->len, fmt, ap);
@@ -62,13 +62,29 @@ int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
/* Available for backwards compatibility */
const char *SDL_GetError(void)
{
const SDL_error *error = SDL_GetErrBuf();
return error->error ? error->str : "";
const SDL_error *error = SDL_GetErrBuf(SDL_FALSE);
if (!error) {
return "";
}
switch (error->error) {
case SDL_ErrorCodeGeneric:
return error->str;
case SDL_ErrorCodeOutOfMemory:
return "Out of memory";
default:
return "";
}
}
void SDL_ClearError(void)
{
SDL_GetErrBuf()->error = 0;
SDL_error *error = SDL_GetErrBuf(SDL_FALSE);
if (error) {
error->error = SDL_ErrorCodeNone;
}
}
/* Very common errors go here */
@@ -76,7 +92,8 @@ int SDL_Error(SDL_errorcode code)
{
switch (code) {
case SDL_ENOMEM:
return SDL_SetError("Out of memory");
SDL_GetErrBuf(SDL_TRUE)->error = SDL_ErrorCodeOutOfMemory;
return -1;
case SDL_EFREAD:
return SDL_SetError("Error reading from datastream");
case SDL_EFWRITE:
@@ -89,16 +106,3 @@ int SDL_Error(SDL_errorcode code)
return SDL_SetError("Unknown SDL error");
}
}
char *SDL_GetErrorMsg(char *errstr, int maxlen)
{
const SDL_error *error = SDL_GetErrBuf();
if (error->error) {
SDL_strlcpy(errstr, error->str, maxlen);
} else {
*errstr = '\0';
}
return errstr;
}