mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-11-21 18:10:26 +01:00
fix exePath in the FileSystem abstraction, it should point to a file.
This commit is contained in:
parent
cb0ad7a57f
commit
b22bd62dc8
|
@ -22,6 +22,43 @@
|
|||
|
||||
ENGINE_API CFileSystem *_pFileSystem = NULL;
|
||||
|
||||
// Stolen from SDL2/src/filesystem/unix/SDL_sysfilesystem.c
|
||||
static char * readSymLink(const char *path)
|
||||
{
|
||||
char *retval = NULL;
|
||||
ssize_t len = 64;
|
||||
ssize_t rc = -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
char *ptr = (char *) SDL_realloc(retval, (size_t) len);
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
break;
|
||||
}
|
||||
|
||||
retval = ptr;
|
||||
|
||||
rc = readlink(path, retval, len);
|
||||
if (rc == -1) {
|
||||
break; /* not a symlink, i/o error, etc. */
|
||||
} else if (rc < len) {
|
||||
retval[rc] = '\0'; /* readlink doesn't null-terminate. */
|
||||
|
||||
/* try to shrink buffer... */
|
||||
ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
|
||||
if (ptr != NULL)
|
||||
retval = ptr; /* oh well if it failed. */
|
||||
|
||||
return retval; /* we're good to go. */
|
||||
}
|
||||
|
||||
len *= 2; /* grow buffer, try again. */
|
||||
}
|
||||
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
class CUnixFileSystem : public CFileSystem
|
||||
{
|
||||
|
@ -77,7 +114,7 @@ BOOL CFileSystem::IsDirectory(const char *fname)
|
|||
|
||||
CUnixFileSystem::CUnixFileSystem(const char *argv0, const char *gamename)
|
||||
{
|
||||
exePath = SDL_GetBasePath();
|
||||
exePath = readSymLink("/proc/self/exe");
|
||||
userDir = SDL_GetPrefPath("Serious Engine", gamename);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user