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
@@ -47,8 +47,7 @@ static char *readSymLink(const char *path)
while (1) {
char *ptr = (char *)SDL_realloc(retval, (size_t)len);
if (ptr == NULL) {
SDL_OutOfMemory();
if (!ptr) {
break;
}
@@ -78,14 +77,13 @@ static char *search_path_for_binary(const char *bin)
char *start = envr;
char *ptr;
if (envr == NULL) {
if (!envr) {
SDL_SetError("No $PATH set");
return NULL;
}
envr = SDL_strdup(envr);
if (envr == NULL) {
SDL_OutOfMemory();
if (!envr) {
return NULL;
}
@@ -110,7 +108,7 @@ static char *search_path_for_binary(const char *bin)
}
}
start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
} while (ptr);
SDL_free(envr);
SDL_free(exe);
@@ -130,8 +128,7 @@ char *SDL_GetBasePath(void)
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
retval = SDL_strdup(fullpath);
if (retval == NULL) {
SDL_OutOfMemory();
if (!retval) {
return NULL;
}
}
@@ -144,15 +141,13 @@ char *SDL_GetBasePath(void)
if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
char *exe, *pwddst;
char *realpathbuf = (char *)SDL_malloc(PATH_MAX + 1);
if (realpathbuf == NULL) {
SDL_OutOfMemory();
if (!realpathbuf) {
return NULL;
}
cmdline = SDL_malloc(len);
if (cmdline == NULL) {
if (!cmdline) {
SDL_free(realpathbuf);
SDL_OutOfMemory();
return NULL;
}
@@ -172,7 +167,7 @@ char *SDL_GetBasePath(void)
}
if (exe) {
if (pwddst == NULL) {
if (!pwddst) {
if (realpath(exe, realpathbuf) != NULL) {
retval = realpathbuf;
}
@@ -188,7 +183,7 @@ char *SDL_GetBasePath(void)
}
}
if (retval == NULL) {
if (!retval) {
SDL_free(realpathbuf);
}
@@ -197,7 +192,7 @@ char *SDL_GetBasePath(void)
#endif
/* is a Linux-style /proc filesystem available? */
if (retval == NULL && (access("/proc", F_OK) == 0)) {
if (!retval && (access("/proc", F_OK) == 0)) {
/* !!! FIXME: after 2.0.6 ships, let's delete this code and just
use the /proc/%llu version. There's no reason to have
two copies of this plus all the #ifdefs. --ryan. */
@@ -209,7 +204,7 @@ char *SDL_GetBasePath(void)
retval = readSymLink("/proc/self/path/a.out");
#else
retval = readSymLink("/proc/self/exe"); /* linux. */
if (retval == NULL) {
if (!retval) {
/* older kernels don't have /proc/self ... try PID version... */
char path[64];
const int rc = SDL_snprintf(path, sizeof(path),
@@ -225,10 +220,9 @@ char *SDL_GetBasePath(void)
#ifdef __SOLARIS__ /* try this as a fallback if /proc didn't pan out */
if (!retval) {
const char *path = getexecname();
if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
if ((path) && (path[0] == '/')) { /* must be absolute path... */
retval = SDL_strdup(path);
if (retval == NULL) {
SDL_OutOfMemory();
if (!retval) {
return NULL;
}
}
@@ -237,9 +231,9 @@ char *SDL_GetBasePath(void)
/* If we had access to argv[0] here, we could check it for a path,
or troll through $PATH looking for it, too. */
if (retval != NULL) { /* chop off filename. */
if (retval) { /* chop off filename. */
char *ptr = SDL_strrchr(retval, '/');
if (ptr != NULL) {
if (ptr) {
*(ptr + 1) = '\0';
} else { /* shouldn't happen, but just in case... */
SDL_free(retval);
@@ -247,10 +241,10 @@ char *SDL_GetBasePath(void)
}
}
if (retval != NULL) {
if (retval) {
/* try to shrink buffer... */
char *ptr = (char *)SDL_realloc(retval, SDL_strlen(retval) + 1);
if (ptr != NULL) {
if (ptr) {
retval = ptr; /* oh well if it failed. */
}
}
@@ -273,18 +267,18 @@ char *SDL_GetPrefPath(const char *org, const char *app)
char *ptr = NULL;
size_t len = 0;
if (app == NULL) {
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (org == NULL) {
if (!org) {
org = "";
}
if (envr == NULL) {
if (!envr) {
/* You end up with "$HOME/.local/share/Game Name 2" */
envr = SDL_getenv("HOME");
if (envr == NULL) {
if (!envr) {
/* we could take heroic measures with /etc/passwd, but oh well. */
SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
return NULL;
@@ -301,8 +295,7 @@ char *SDL_GetPrefPath(const char *org, const char *app)
len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
retval = (char *)SDL_malloc(len);
if (retval == NULL) {
SDL_OutOfMemory();
if (!retval) {
return NULL;
}
@@ -372,15 +365,15 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
home_dir = SDL_getenv ("HOME");
if (home_dir == NULL)
if (!home_dir)
goto error;
config_home = SDL_getenv ("XDG_CONFIG_HOME");
if (config_home == NULL || config_home[0] == 0)
if (!config_home || config_home[0] == 0)
{
l = SDL_strlen (home_dir) + SDL_strlen ("/.config/user-dirs.dirs") + 1;
config_file = (char*) SDL_malloc (l);
if (config_file == NULL)
if (!config_file)
goto error;
SDL_strlcpy (config_file, home_dir, l);
@@ -390,7 +383,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
{
l = SDL_strlen (config_home) + SDL_strlen ("/user-dirs.dirs") + 1;
config_file = (char*) SDL_malloc (l);
if (config_file == NULL)
if (!config_file)
goto error;
SDL_strlcpy (config_file, config_home, l);
@@ -399,7 +392,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
file = fopen (config_file, "r");
SDL_free (config_file);
if (file == NULL)
if (!file)
goto error;
user_dir = NULL;
@@ -452,7 +445,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
{
l = SDL_strlen (home_dir) + 1 + SDL_strlen (p) + 1;
user_dir = (char*) SDL_malloc (l);
if (user_dir == NULL)
if (!user_dir)
goto error2;
SDL_strlcpy (user_dir, home_dir, l);
@@ -461,7 +454,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
else
{
user_dir = (char*) SDL_malloc (SDL_strlen (p) + 1);
if (user_dir == NULL)
if (!user_dir)
goto error2;
*user_dir = 0;
@@ -493,12 +486,12 @@ static char *xdg_user_dir_lookup (const char *type)
char *dir, *home_dir, *user_dir;
dir = xdg_user_dir_lookup_with_fallback(type, NULL);
if (dir != NULL)
if (dir)
return dir;
home_dir = SDL_getenv("HOME");
if (home_dir == NULL)
if (!home_dir)
return NULL;
/* Special case desktop for historical compatibility */
@@ -506,7 +499,7 @@ static char *xdg_user_dir_lookup (const char *type)
{
user_dir = (char*) SDL_malloc(SDL_strlen(home_dir) +
SDL_strlen("/Desktop") + 1);
if (user_dir == NULL)
if (!user_dir)
return NULL;
strcpy(user_dir, home_dir);
@@ -541,13 +534,7 @@ char *SDL_GetUserFolder(SDL_Folder folder)
return NULL;
}
retval = SDL_strdup(param);
if (!retval) {
SDL_OutOfMemory();
}
return retval;
return SDL_strdup(param);
case SDL_FOLDER_DESKTOP:
param = "DESKTOP";