mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 19:24:09 +02:00
update SDL3 to 3.2.0
This commit is contained in:
+120
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 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
|
||||
@@ -20,14 +20,7 @@ static SDL_EnumerationResult SDLCALL enum_callback(void *userdata, const char *o
|
||||
SDL_PathInfo info;
|
||||
char *fullpath = NULL;
|
||||
|
||||
/* you can use '/' for a path separator on Windows, but to make the log output look correct, we'll #ifdef this... */
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
const char *pathsep = "\\";
|
||||
#else
|
||||
const char *pathsep = "/";
|
||||
#endif
|
||||
|
||||
if (SDL_asprintf(&fullpath, "%s%s%s", origdir, *origdir ? pathsep : "", fname) < 0) {
|
||||
if (SDL_asprintf(&fullpath, "%s%s", origdir, fname) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
return SDL_ENUM_FAILURE;
|
||||
}
|
||||
@@ -43,7 +36,7 @@ static SDL_EnumerationResult SDLCALL enum_callback(void *userdata, const char *o
|
||||
} else {
|
||||
type = "OTHER";
|
||||
}
|
||||
SDL_Log("%s (type=%s, size=%" SDL_PRIu64 ", create=%" SDL_PRIu64 ", mod=%" SDL_PRIu64 ", access=%" SDL_PRIu64 ")",
|
||||
SDL_Log("DIRECTORY %s (type=%s, size=%" SDL_PRIu64 ", create=%" SDL_PRIu64 ", mod=%" SDL_PRIu64 ", access=%" SDL_PRIu64 ")",
|
||||
fullpath, type, info.size, info.modify_time, info.create_time, info.access_time);
|
||||
|
||||
if (info.type == SDL_PATHTYPE_DIRECTORY) {
|
||||
@@ -58,6 +51,42 @@ static SDL_EnumerationResult SDLCALL enum_callback(void *userdata, const char *o
|
||||
}
|
||||
|
||||
|
||||
static SDL_EnumerationResult SDLCALL enum_storage_callback(void *userdata, const char *origdir, const char *fname)
|
||||
{
|
||||
SDL_Storage *storage = (SDL_Storage *) userdata;
|
||||
SDL_PathInfo info;
|
||||
char *fullpath = NULL;
|
||||
|
||||
if (SDL_asprintf(&fullpath, "%s%s", origdir, fname) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
return SDL_ENUM_FAILURE;
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, fullpath, &info)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't stat '%s': %s", fullpath, SDL_GetError());
|
||||
} else {
|
||||
const char *type;
|
||||
if (info.type == SDL_PATHTYPE_FILE) {
|
||||
type = "FILE";
|
||||
} else if (info.type == SDL_PATHTYPE_DIRECTORY) {
|
||||
type = "DIRECTORY";
|
||||
} else {
|
||||
type = "OTHER";
|
||||
}
|
||||
SDL_Log("STORAGE %s (type=%s, size=%" SDL_PRIu64 ", create=%" SDL_PRIu64 ", mod=%" SDL_PRIu64 ", access=%" SDL_PRIu64 ")",
|
||||
fullpath, type, info.size, info.modify_time, info.create_time, info.access_time);
|
||||
|
||||
if (info.type == SDL_PATHTYPE_DIRECTORY) {
|
||||
if (!SDL_EnumerateStorageDirectory(storage, fullpath, enum_storage_callback, userdata)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Enumeration failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_free(fullpath);
|
||||
return SDL_ENUM_CONTINUE; /* keep going */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDLTest_CommonState *state;
|
||||
@@ -118,8 +147,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (base_path) {
|
||||
char **globlist;
|
||||
SDL_Storage *storage = NULL;
|
||||
SDL_IOStream *stream;
|
||||
const char *text = "foo\n";
|
||||
SDL_PathInfo pathinfo;
|
||||
|
||||
if (!SDL_EnumerateDirectory(base_path, enum_callback, NULL)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Base path enumeration failed!");
|
||||
@@ -131,7 +162,7 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; globlist[i]; i++) {
|
||||
SDL_Log("GLOB[%d]: '%s'", i, globlist[i]);
|
||||
SDL_Log("DIRECTORY GLOB[%d]: '%s'", i, globlist[i]);
|
||||
}
|
||||
SDL_free(globlist);
|
||||
}
|
||||
@@ -198,6 +229,84 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_IOFromFile('testfilesystem-A', 'w') failed: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
storage = SDL_OpenFileStorage(base_path);
|
||||
if (!storage) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open base path storage object: %s", SDL_GetError());
|
||||
} else {
|
||||
if (!SDL_EnumerateStorageDirectory(storage, "CMakeFiles", enum_storage_callback, storage)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Storage Base path enumeration failed!");
|
||||
}
|
||||
|
||||
globlist = SDL_GlobStorageDirectory(storage, "", "C*/test*/T?st*", SDL_GLOB_CASEINSENSITIVE, NULL);
|
||||
if (!globlist) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Base path globbing failed!");
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; globlist[i]; i++) {
|
||||
SDL_Log("STORAGE GLOB[%d]: '%s'", i, globlist[i]);
|
||||
}
|
||||
SDL_free(globlist);
|
||||
}
|
||||
|
||||
/* these should fail: */
|
||||
if (!SDL_GetStoragePathInfo(storage, "CMakeFiles/../testsprite.c", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with internal '..' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with internal '..' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "CMakeFiles/./TargetDirectories.txt", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with internal '.' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with internal '.' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "../test", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with leading '..' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with leading '..' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "./CMakeFiles", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with leading '.' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with leading '.' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "CMakeFiles/..", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with trailing '..' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with trailing '..' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "CMakeFiles/.", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with trailing '.' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with trailing '.' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "..", &pathinfo)) {
|
||||
SDL_Log("Storage access on path '..' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path '..' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, ".", &pathinfo)) {
|
||||
SDL_Log("Storage access on path '.' refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path '.' accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
if (!SDL_GetStoragePathInfo(storage, "CMakeFiles\\TargetDirectories.txt", &pathinfo)) {
|
||||
SDL_Log("Storage access on path with Windows separator refused correctly.");
|
||||
} else {
|
||||
SDL_Log("Storage access on path with Windows separator accepted INCORRECTLY.");
|
||||
}
|
||||
|
||||
SDL_CloseStorage(storage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
Reference in New Issue
Block a user