1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Make basePath and pathSep global variables

While reviewing #272, I noticed that the PR was passing these two
arguments through a helper function, even though they really shouldn't
ever change. To obviate the need to pass these through, I'm making them
global variables.

pathSep is just a string literal from PhysFS, while basePath is a whole
complicated calculation from SDL and needs to be freed. It will be freed
upon filesystem deinit (as is done with PhysFS and the STDIN buffer).

Additionally the logic in FILESYSTEM_init is simplified by no longer
needing to keep a retval variable or use gotos to free basePath in
there.
This commit is contained in:
Misa 2022-03-09 11:55:38 -08:00
parent 0622035424
commit 6fffa5c11d

View file

@ -34,6 +34,8 @@ static int mkdir(char* path, int mode)
#define MAX_PATH PATH_MAX #define MAX_PATH PATH_MAX
#endif #endif
static const char* pathSep = NULL;
static char* basePath = NULL;
static char saveDir[MAX_PATH] = {'\0'}; static char saveDir[MAX_PATH] = {'\0'};
static char levelDir[MAX_PATH] = {'\0'}; static char levelDir[MAX_PATH] = {'\0'};
@ -63,9 +65,8 @@ static const PHYSFS_Allocator allocator = {
int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath) int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
{ {
char output[MAX_PATH]; char output[MAX_PATH];
int retval;
const char* pathSep = PHYSFS_getDirSeparator(); pathSep = PHYSFS_getDirSeparator();
char* basePath;
PHYSFS_setAllocator(&allocator); PHYSFS_setAllocator(&allocator);
@ -170,8 +171,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
"\nor get it from the free Make and Play Edition.", "\nor get it from the free Make and Play Edition.",
NULL NULL
); );
retval = 0; return 0;
goto end;
} }
SDL_snprintf(output, sizeof(output), "%s%s", basePath, "gamecontrollerdb.txt"); SDL_snprintf(output, sizeof(output), "%s%s", basePath, "gamecontrollerdb.txt");
@ -179,11 +179,7 @@ int FILESYSTEM_init(char *argvZero, char* baseDir, char *assetsPath)
{ {
vlog_info("gamecontrollerdb.txt not found!"); vlog_info("gamecontrollerdb.txt not found!");
} }
retval = 1; return 1;
end:
SDL_free(basePath);
return retval;
} }
static unsigned char* stdin_buffer = NULL; static unsigned char* stdin_buffer = NULL;
@ -200,6 +196,8 @@ void FILESYSTEM_deinit(void)
SDL_free(stdin_buffer); SDL_free(stdin_buffer);
stdin_buffer = NULL; stdin_buffer = NULL;
} }
SDL_free(basePath);
basePath = NULL;
} }
char *FILESYSTEM_getUserSaveDirectory(void) char *FILESYSTEM_getUserSaveDirectory(void)