add filesystem driver

Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
Arnav Bhatt
2024-06-23 03:11:17 +05:30
parent e432f80a05
commit dd949a36ee
3 changed files with 58 additions and 3 deletions

View File

@@ -41,7 +41,7 @@ loadso_OBJS = src/loadso/dummy/SDL_sysloadso.o
power_OBJS = src/power/SDL_power.o power_OBJS = src/power/SDL_power.o
filesystem_OBJS = src/filesystem/dummy/SDL_sysfilesystem.o filesystem_OBJS = src/filesystem/kolibri/SDL_sysfilesystem.o
locale_OBJS = src/locale/SDL_locale.o src/locale/dummy/SDL_syslocale.o locale_OBJS = src/locale/SDL_locale.o src/locale/dummy/SDL_syslocale.o

View File

@@ -116,7 +116,7 @@
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */ /* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
#define SDL_LOADSO_DISABLED 1 #define SDL_LOADSO_DISABLED 1
/* Enable the dummy filesystem driver (src/filesystem/dummy/\*.c) */ /* Enable the Kolibri filesystem driver (src/filesystem/kolibri/\*.c) */
#define SDL_FILESYSTEM_DUMMY 1 #define SDL_FILESYSTEM_KOLIBRI 1
#endif /* SDL_config_kolibri_h_ */ #endif /* SDL_config_kolibri_h_ */

View File

@@ -0,0 +1,55 @@
#include "../../SDL_internal.h"
#ifdef SDL_FILESYSTEM_KOLIBRI
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* System dependent filesystem routines */
#include <sys/ksys.h>
#include "SDL_error.h"
#include "SDL_filesystem.h"
char *SDL_GetBasePath(void)
{
char *retval = NULL;
size_t len;
char cwd[FILENAME_MAX];
_ksys_getcwd(cwd, sizeof(cwd));
len = SDL_strlen(cwd) + 2;
retval = (char *)SDL_malloc(len);
SDL_snprintf(retval, len, "%s/", cwd);
return retval;
}
char *SDL_GetPrefPath(const char *org, const char *app)
{
char *retval = NULL;
size_t len;
char *base = SDL_GetBasePath();
if (!app) {
SDL_InvalidParamError("app");
return NULL;
}
if (!org) {
org = "";
}
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
retval = (char *)SDL_malloc(len);
if (*org) {
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
} else {
SDL_snprintf(retval, len, "%s%s/", base, app);
}
free(base);
_ksys_mkdir(retval);
return retval;
}
#endif