update SDL3 from 3.2.20 to 3.4.2

This commit is contained in:
Sven Balzer
2026-04-01 18:25:03 +02:00
parent 1daf4d79f1
commit 05b19704f8
1626 changed files with 124218 additions and 191491 deletions
+26 -13
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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,7 +27,7 @@
bool SDL_RemovePath(const char *path)
{
if (!path) {
CHECK_PARAM(!path) {
return SDL_InvalidParamError("path");
}
return SDL_SYS_RemovePath(path);
@@ -35,9 +35,10 @@ bool SDL_RemovePath(const char *path)
bool SDL_RenamePath(const char *oldpath, const char *newpath)
{
if (!oldpath) {
CHECK_PARAM(!oldpath) {
return SDL_InvalidParamError("oldpath");
} else if (!newpath) {
}
CHECK_PARAM(!newpath) {
return SDL_InvalidParamError("newpath");
}
return SDL_SYS_RenamePath(oldpath, newpath);
@@ -45,9 +46,10 @@ bool SDL_RenamePath(const char *oldpath, const char *newpath)
bool SDL_CopyFile(const char *oldpath, const char *newpath)
{
if (!oldpath) {
CHECK_PARAM(!oldpath) {
return SDL_InvalidParamError("oldpath");
} else if (!newpath) {
}
CHECK_PARAM(!newpath) {
return SDL_InvalidParamError("newpath");
}
return SDL_SYS_CopyFile(oldpath, newpath);
@@ -55,7 +57,7 @@ bool SDL_CopyFile(const char *oldpath, const char *newpath)
bool SDL_CreateDirectory(const char *path)
{
if (!path) {
CHECK_PARAM(!path) {
return SDL_InvalidParamError("path");
}
@@ -116,9 +118,10 @@ bool SDL_CreateDirectory(const char *path)
bool SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata)
{
if (!path) {
CHECK_PARAM(!path) {
return SDL_InvalidParamError("path");
} else if (!callback) {
}
CHECK_PARAM(!callback) {
return SDL_InvalidParamError("callback");
}
return SDL_SYS_EnumerateDirectory(path, callback, userdata);
@@ -133,10 +136,9 @@ bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info)
}
SDL_zerop(info);
if (!path) {
CHECK_PARAM(!path) {
return SDL_InvalidParamError("path");
}
return SDL_SYS_GetPathInfo(path, info);
}
@@ -364,7 +366,7 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob
}
*count = 0;
if (!path) {
CHECK_PARAM(!path) {
SDL_InvalidParamError("path");
return NULL;
}
@@ -488,7 +490,8 @@ static char *CachedUserFolders[SDL_FOLDER_COUNT];
const char *SDL_GetUserFolder(SDL_Folder folder)
{
const int idx = (int) folder;
if ((idx < 0) || (idx >= SDL_arraysize(CachedUserFolders))) {
CHECK_PARAM((idx < 0) || (idx >= SDL_arraysize(CachedUserFolders))) {
SDL_InvalidParamError("folder");
return NULL;
}
@@ -502,6 +505,16 @@ const char *SDL_GetUserFolder(SDL_Folder folder)
char *SDL_GetPrefPath(const char *org, const char *app)
{
CHECK_PARAM(!app) {
SDL_InvalidParamError("app");
return NULL;
}
// if org is NULL, just make it "" so backends don't have to check both.
if (!org) {
org = "";
}
return SDL_SYS_GetPrefPath(org, app);
}
+1 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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 -1
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -31,9 +31,7 @@
char *SDL_SYS_GetBasePath(void)
{
// The current working directory is / on Android
SDL_Unsupported();
return NULL;
return SDL_strdup("./");
}
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -69,14 +69,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
char *result = NULL;
NSArray *array;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
#ifndef SDL_PLATFORM_TVOS
array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
#else
@@ -106,13 +98,12 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
result = (char *)SDL_malloc(len);
if (result != NULL) {
char *ptr;
if (*org) {
SDL_snprintf(result, len, "%s/%s/%s/", base, org, app);
} else {
SDL_snprintf(result, len, "%s/%s/", base, app);
}
for (ptr = result + 1; *ptr; ptr++) {
for (char *ptr = result + 1; *ptr; ptr++) {
if (*ptr == '/') {
*ptr = '\0';
mkdir(result, 0700);
@@ -136,7 +127,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder)
return NULL;
#else
char *result = NULL;
const char* base;
const char *base;
NSArray *array;
NSSearchPathDirectory dir;
NSString *str;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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,12 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder)
char *SDL_SYS_GetCurrentDirectory(void)
{
SDL_Unsupported();
return NULL;
const char *base = SDL_GetBasePath();
if (!base) {
return NULL;
}
return SDL_strdup(base);
}
#endif // SDL_FILESYSTEM_DUMMY || SDL_FILESYSTEM_DISABLED
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -42,17 +42,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
const char *append = "/libsdl/";
char *result;
char *ptr = NULL;
size_t len = 0;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
const size_t len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
result = (char *)SDL_malloc(len);
if (!result) {
return NULL;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -90,11 +90,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
HRESULT result;
const char *csid = SDL_GetHint("SDL_GDK_SERVICE_CONFIGURATION_ID");
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
// This should be set before calling SDL_GetPrefPath!
if (!csid) {
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "Set SDL_GDK_SERVICE_CONFIGURATION_ID before calling SDL_GetPrefPath!");
@@ -111,7 +106,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
return NULL;
}
folderPath = (char*) SDL_malloc(MAX_PATH);
folderPath = (char *)SDL_malloc(MAX_PATH);
do {
result = XGameSaveFilesGetFolderWithUiResult(&block, MAX_PATH, folderPath);
} while (result == E_PENDING);
@@ -142,9 +137,12 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder)
return NULL;
}
// TODO
char *SDL_SYS_GetCurrentDirectory(void)
{
SDL_Unsupported();
return NULL;
const char *base = SDL_GetBasePath();
if (!base) {
return NULL;
}
return SDL_strdup(base);
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -72,14 +72,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
const char *append = "/config/settings/";
size_t len = SDL_strlen(home);
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
if (!len || (home[len - 1] == '/')) {
++append; // home empty or ends with separator, skip the one from append
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -43,11 +43,6 @@ char *SDL_SYS_GetBasePath(void)
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
{
char *pref_path = NULL;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
pref_path = MakePrefPath(app);
if (!pref_path) {
return NULL;
@@ -0,0 +1,67 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
extern void NGAGE_GetAppPath(char *path);
char *SDL_SYS_GetBasePath(void)
{
char app_path[512];
NGAGE_GetAppPath(app_path);
char *base_path = SDL_strdup(app_path);
return base_path;
}
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
{
char *pref_path = NULL;
if (SDL_asprintf(&pref_path, "C:/System/Apps/%s/%s/", org ? org : "SDL_App", app) < 0) {
return NULL;
}
return pref_path;
}
char *SDL_SYS_GetUserFolder(SDL_Folder folder)
{
const char *folder_path = NULL;
switch (folder)
{
case SDL_FOLDER_HOME:
folder_path = "C:/";
break;
case SDL_FOLDER_PICTURES:
folder_path = "C:/Nokia/Pictures/";
break;
case SDL_FOLDER_SAVEDGAMES:
folder_path = "C:/";
break;
case SDL_FOLDER_SCREENSHOTS:
folder_path = "C:/Nokia/Pictures/";
break;
case SDL_FOLDER_VIDEOS:
folder_path = "C:/Nokia/Videos/";
break;
default:
folder_path = "C:/Nokia/Others/";
break;
}
return SDL_strdup(folder_path);
}
@@ -0,0 +1,68 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "SDL_internal.h"
#ifdef __cplusplus
}
#endif
#include <e32base.h>
#include <e32std.h>
#include <f32file.h>
#include <utf.h>
#ifdef __cplusplus
extern "C" {
#endif
void NGAGE_GetAppPath(char *path)
{
TBuf<512> aPath;
TFileName fullExePath = RProcess().FileName();
TParsePtrC parser(fullExePath);
aPath.Copy(parser.DriveAndPath());
TBuf8<512> utf8Path; // Temporary buffer for UTF-8 data.
CnvUtfConverter::ConvertFromUnicodeToUtf8(utf8Path, aPath);
// Copy UTF-8 data to the provided char* buffer.
strncpy(path, (const char *)utf8Path.Ptr(), utf8Path.Length());
path[utf8Path.Length()] = '\0';
// Replace backslashes with forward slashes.
for (int i = 0; i < utf8Path.Length(); i++)
{
if (path[i] == '\\')
{
path[i] = '/';
}
}
}
#ifdef __cplusplus
}
#endif
+220 -14
View File
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -35,30 +35,70 @@
#include <sys/stat.h>
#include <unistd.h>
#ifdef SDL_PLATFORM_ANDROID
#include "../../core/android/SDL_android.h"
#endif
bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata)
{
char *apath = NULL; // absolute path (for Android, iOS, etc). Overrides `path`.
#if defined(SDL_PLATFORM_ANDROID) || defined(SDL_PLATFORM_IOS)
if (*path != '/') {
#ifdef SDL_PLATFORM_ANDROID
SDL_asprintf(&apath, "%s/%s", SDL_GetAndroidInternalStoragePath(), path);
#elif defined(SDL_PLATFORM_IOS)
char *base = SDL_GetPrefPath("", "");
if (!base) {
return false;
}
SDL_asprintf(&apath, "%s%s", base, path);
SDL_free(base);
#endif
if (!apath) {
return false;
}
}
#elif 0 // this is just for testing that `apath` works when you aren't on iOS or Android.
if (*path != '/') {
char *c = SDL_SYS_GetCurrentDirectory();
SDL_asprintf(&apath, "%s%s", c, path);
SDL_free(c);
if (!apath) {
return false;
}
}
#endif
char *pathwithsep = NULL;
int pathwithseplen = SDL_asprintf(&pathwithsep, "%s/", path);
int pathwithseplen = SDL_asprintf(&pathwithsep, "%s/", apath ? apath : path);
const size_t extralen = apath ? (SDL_strlen(apath) - SDL_strlen(path)) : 0;
SDL_free(apath);
if ((pathwithseplen == -1) || (!pathwithsep)) {
return false;
}
// trim down to a single path separator at the end, in case the caller added one or more.
pathwithseplen--;
while ((pathwithseplen >= 0) && (pathwithsep[pathwithseplen] == '/')) {
while ((pathwithseplen > 0) && (pathwithsep[pathwithseplen - 1] == '/')) {
pathwithsep[pathwithseplen--] = '\0';
}
DIR *dir = opendir(pathwithsep);
if (!dir) {
#ifdef SDL_PLATFORM_ANDROID // Maybe it's an asset...?
const bool retval = Android_JNI_EnumerateAssetDirectory(pathwithsep + extralen, cb, userdata);
SDL_free(pathwithsep);
return retval;
#else
SDL_free(pathwithsep);
return SDL_SetError("Can't open directory: %s", strerror(errno));
#endif
}
// make sure there's a path separator at the end now for the actual callback.
pathwithsep[++pathwithseplen] = '/';
pathwithsep[++pathwithseplen] = '\0';
SDL_EnumerationResult result = SDL_ENUM_CONTINUE;
struct dirent *ent;
while ((result == SDL_ENUM_CONTINUE) && ((ent = readdir(dir)) != NULL)) {
@@ -66,7 +106,7 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
if ((SDL_strcmp(name, ".") == 0) || (SDL_strcmp(name, "..") == 0)) {
continue;
}
result = cb(userdata, pathwithsep, name);
result = cb(userdata, pathwithsep + extralen, name);
}
closedir(dir);
@@ -78,7 +118,41 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
bool SDL_SYS_RemovePath(const char *path)
{
int rc = remove(path);
int rc;
#ifdef SDL_PLATFORM_ANDROID
if (*path == '/') {
rc = remove(path);
} else {
char *apath = NULL;
SDL_asprintf(&apath, "%s/%s", SDL_GetAndroidInternalStoragePath(), path);
if (!apath) {
return false;
}
rc = remove(apath);
SDL_free(apath);
}
#elif defined(SDL_PLATFORM_IOS)
if (*path == '/') {
rc = remove(path);
} else {
char *base = SDL_GetPrefPath("", "");
if (!base) {
return false;
}
char *apath = NULL;
SDL_asprintf(&apath, "%s%s", base, path);
SDL_free(base);
if (!apath) {
return false;
}
rc = remove(apath);
SDL_free(apath);
}
#else
rc = remove(path);
#endif
if (rc < 0) {
if (errno == ENOENT) {
// It's already gone, this is a success
@@ -91,7 +165,65 @@ bool SDL_SYS_RemovePath(const char *path)
bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath)
{
if (rename(oldpath, newpath) < 0) {
int rc;
#ifdef SDL_PLATFORM_ANDROID
char *aoldpath = NULL;
char *anewpath = NULL;
if (*oldpath != '/') {
SDL_asprintf(&aoldpath, "%s/%s", SDL_GetAndroidInternalStoragePath(), oldpath);
if (!aoldpath) {
return false;
}
oldpath = aoldpath;
}
if (*newpath != '/') {
SDL_asprintf(&anewpath, "%s/%s", SDL_GetAndroidInternalStoragePath(), newpath);
if (!anewpath) {
SDL_free(aoldpath);
return false;
}
newpath = anewpath;
}
rc = rename(oldpath, newpath);
SDL_free(aoldpath);
SDL_free(anewpath);
#elif defined(SDL_PLATFORM_IOS)
char *base = NULL;
if (*oldpath != '/' || *newpath != '/') {
base = SDL_GetPrefPath("", "");
if (!base) {
return false;
}
}
char *aoldpath = NULL;
char *anewpath = NULL;
if (*oldpath != '/') {
SDL_asprintf(&aoldpath, "%s%s", base, oldpath);
if (!aoldpath) {
SDL_free(base);
return false;
}
oldpath = aoldpath;
}
if (*newpath != '/') {
SDL_asprintf(&anewpath, "%s%s", base, newpath);
if (!anewpath) {
SDL_free(base);
SDL_free(aoldpath);
return false;
}
newpath = anewpath;
}
rc = rename(oldpath, newpath);
SDL_free(base);
SDL_free(aoldpath);
SDL_free(anewpath);
#else
rc = rename(oldpath, newpath);
#endif
if (rc < 0) {
return SDL_SetError("Can't rename path: %s", strerror(errno));
}
return true;
@@ -154,7 +286,41 @@ done:
bool SDL_SYS_CreateDirectory(const char *path)
{
const int rc = mkdir(path, 0770);
int rc;
#ifdef SDL_PLATFORM_ANDROID
if (*path == '/') {
rc = mkdir(path, 0770);
} else {
char *apath = NULL;
SDL_asprintf(&apath, "%s/%s", SDL_GetAndroidInternalStoragePath(), path);
if (!apath) {
return false;
}
rc = mkdir(apath, 0770);
SDL_free(apath);
}
#elif defined(SDL_PLATFORM_IOS)
if (*path == '/') {
rc = mkdir(path, 0770);
} else {
char *base = SDL_GetPrefPath("", "");
if (!base) {
return false;
}
char *apath = NULL;
SDL_asprintf(&apath, "%s%s", base, path);
SDL_free(base);
if (!apath) {
return false;
}
rc = mkdir(apath, 0770);
SDL_free(apath);
}
#else
rc = mkdir(path, 0770);
#endif
if (rc < 0) {
const int origerrno = errno;
if (origerrno == EEXIST) {
@@ -171,7 +337,48 @@ bool SDL_SYS_CreateDirectory(const char *path)
bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info)
{
struct stat statbuf;
const int rc = stat(path, &statbuf);
int rc;
#ifdef SDL_PLATFORM_ANDROID
if (*path == '/') {
rc = stat(path, &statbuf);
} else {
char *apath = NULL;
SDL_asprintf(&apath, "%s/%s", SDL_GetAndroidInternalStoragePath(), path);
if (!apath) {
return false;
}
rc = stat(apath, &statbuf);
SDL_free(apath);
}
if (rc < 0) {
return Android_JNI_GetAssetPathInfo(path, info);
}
#elif defined(SDL_PLATFORM_IOS)
if (*path == '/') {
rc = stat(path, &statbuf);
} else {
char *base = SDL_GetPrefPath("", "");
if (!base) {
return false;
}
char *apath = NULL;
SDL_asprintf(&apath, "%s%s", base, path);
SDL_free(base);
if (!apath) {
return false;
}
rc = stat(apath, &statbuf);
SDL_free(apath);
if (rc < 0) {
rc = stat(path, &statbuf);
}
}
#else
rc = stat(path, &statbuf);
#endif
if (rc < 0) {
return SDL_SetError("Can't stat: %s", strerror(errno));
} else if (S_ISREG(statbuf.st_mode)) {
@@ -203,7 +410,7 @@ bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info)
return true;
}
// Note that this isn't actually part of filesystem, not fsops, but everything that uses posix fsops uses this implementation, even with separate filesystem code.
// Note that this is actually part of filesystem, not fsops, but everything that uses posix fsops uses this implementation, even with separate filesystem code.
char *SDL_SYS_GetCurrentDirectory(void)
{
size_t buflen = 64;
@@ -243,4 +450,3 @@ char *SDL_SYS_GetCurrentDirectory(void)
}
#endif // SDL_FSOPS_POSIX
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -80,15 +80,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
char *result = NULL;
size_t len;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
const char *base = SDL_GetBasePath();
if (!base) {
return NULL;
@@ -102,7 +93,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
} else {
SDL_snprintf(result, len, "%s%s/", base, app);
}
recursive_mkdir(result);
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -49,22 +49,12 @@ char *SDL_SYS_GetBasePath(void)
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
{
char *result = NULL;
size_t len;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
const char *base = SDL_GetBasePath();
if (!base) {
return NULL;
}
if (!org) {
org = "";
}
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
result = (char *)SDL_malloc(len);
if (result) {
if (*org) {
@@ -72,7 +62,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
} else {
SDL_snprintf(result, len, "%s%s/", base, app);
}
mkdir(result, 0755);
}
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -155,23 +155,14 @@ char *SDL_SYS_GetBasePath(void)
char *SDL_SYS_GetPrefPath(const char *org, const char *app)
{
char *canon, *dir, *result;
size_t len;
_kernel_oserror *error;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
canon = canonicalisePath("<Choices$Write>", "Run$Path");
if (!canon) {
return NULL;
}
len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
const size_t len = SDL_strlen(canon) + SDL_strlen(org) + SDL_strlen(app) + 4;
dir = (char *)SDL_malloc(len);
if (!dir) {
SDL_free(canon);
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -78,7 +78,7 @@ static char *search_path_for_binary(const char *bin)
char *envr;
size_t alloc_size;
char *exe = NULL;
char *start = envr;
char *start;
char *ptr;
if (!envr_real) {
@@ -86,7 +86,7 @@ static char *search_path_for_binary(const char *bin)
return NULL;
}
envr = SDL_strdup(envr_real);
start = envr = SDL_strdup(envr_real);
if (!envr) {
return NULL;
}
@@ -269,15 +269,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
const char *append;
char *result = NULL;
char *ptr = NULL;
size_t len = 0;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
if (!envr) {
// You end up with "$HOME/.local/share/Game Name 2"
@@ -292,7 +283,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
append = "/";
}
len = SDL_strlen(envr);
size_t len = SDL_strlen(envr);
if (envr[len - 1] == '/') {
append += 1;
}
@@ -377,7 +368,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
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);
config_file = (char *)SDL_malloc (l);
if (!config_file)
goto error;
@@ -387,7 +378,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
else
{
l = SDL_strlen (config_home) + SDL_strlen ("/user-dirs.dirs") + 1;
config_file = (char*) SDL_malloc (l);
config_file = (char *)SDL_malloc (l);
if (!config_file)
goto error;
@@ -449,7 +440,7 @@ static char *xdg_user_dir_lookup_with_fallback (const char *type, const char *fa
if (relative)
{
l = SDL_strlen (home_dir) + 1 + SDL_strlen (p) + 1;
user_dir = (char*) SDL_malloc (l);
user_dir = (char *)SDL_malloc (l);
if (!user_dir)
goto error2;
@@ -458,7 +449,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);
user_dir = (char *)SDL_malloc (SDL_strlen (p) + 1);
if (!user_dir)
goto error2;
@@ -503,7 +494,7 @@ static char *xdg_user_dir_lookup (const char *type)
// Special case desktop for historical compatibility
if (SDL_strcmp(type, "DESKTOP") == 0) {
size_t length = SDL_strlen(home_dir) + SDL_strlen("/Desktop") + 1;
user_dir = (char*) SDL_malloc(length);
user_dir = (char *)SDL_malloc(length);
if (!user_dir)
return NULL;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -46,19 +46,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
const char *envr = "ux0:/data/";
char *result = NULL;
char *ptr = NULL;
size_t len = 0;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
len = SDL_strlen(envr);
len += SDL_strlen(org) + SDL_strlen(app) + 3;
size_t len = SDL_strlen(envr) + SDL_strlen(org) + SDL_strlen(app) + 3;
result = (char *)SDL_malloc(len);
if (!result) {
return NULL;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -110,14 +110,6 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
size_t new_wpath_len = 0;
BOOL api_result = FALSE;
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
hr = SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path);
if (!SUCCEEDED(hr)) {
WIN_SetErrorFromHRESULT("Couldn't locate our prefpath", hr);
@@ -181,7 +173,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app)
char *SDL_SYS_GetUserFolder(SDL_Folder folder)
{
typedef HRESULT (WINAPI *pfnSHGetKnownFolderPath)(REFGUID /* REFKNOWNFOLDERID */, DWORD, HANDLE, PWSTR*);
HMODULE lib = LoadLibrary(L"Shell32.dll");
HMODULE lib = LoadLibraryW(L"Shell32.dll");
pfnSHGetKnownFolderPath pSHGetKnownFolderPath = NULL;
char *result = NULL;
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2026 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
@@ -29,6 +29,10 @@
#include "../../core/windows/SDL_windows.h"
#include "../SDL_sysfilesystem.h"
#ifndef COPY_FILE_NO_BUFFERING
#define COPY_FILE_NO_BUFFERING 0x00001000
#endif
bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback cb, void *userdata)
{
SDL_EnumerationResult result = SDL_ENUM_CONTINUE;
@@ -53,7 +57,7 @@ bool SDL_SYS_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback
// trim down to a single path separator at the end, in case the caller added one or more.
patternlen--;
while ((patternlen >= 0) && ((pattern[patternlen] == '\\') || (pattern[patternlen] == '/'))) {
while ((patternlen > 0) && ((pattern[patternlen] == '\\') || (pattern[patternlen] == '/'))) {
pattern[patternlen--] ='\0';
}
pattern[++patternlen] = '\\';