diff --git a/code/sys/sys_local.h b/code/sys/sys_local.h index a0d6dc24..ce9f99b3 100644 --- a/code/sys/sys_local.h +++ b/code/sys/sys_local.h @@ -50,6 +50,9 @@ unsigned int CON_LogSize( void ); unsigned int CON_LogWrite( const char *in ); unsigned int CON_LogRead( char *out, unsigned int outSize ); +char *Sys_BinaryPath( void ); +char *Sys_BinaryPathRelative( const char *relative ); + #ifdef __APPLE__ char *Sys_StripAppBundle( char *pwd ); #endif diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index 44fb0981..6101fded 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -721,7 +721,9 @@ char *Sys_ParseProtocolUri( const char *uri ) #endif #ifndef DEFAULT_BASEDIR -# ifdef __APPLE__ +# if defined(DEFAULT_RELATIVE_BASEDIR) +# define DEFAULT_BASEDIR Sys_BinaryPathRelative(DEFAULT_RELATIVE_BASEDIR) +# elif defined(__APPLE__) # define DEFAULT_BASEDIR Sys_StripAppBundle(Sys_BinaryPath()) # else # define DEFAULT_BASEDIR Sys_BinaryPath() diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index 07de6500..53593600 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include #include #include @@ -352,6 +353,24 @@ char *Sys_Cwd( void ) return cwd; } +/* +================== +Sys_BinaryPathRelative +================== +*/ +char *Sys_BinaryPathRelative(const char *relative) +{ + static char resolved[MAX_OSPATH]; + char combined[MAX_OSPATH]; + + snprintf(combined, sizeof(combined), "%s/%s", Sys_BinaryPath(), relative); + + if (!realpath(combined, resolved)) + return NULL; + + return resolved; +} + /* ============================================================== diff --git a/code/sys/sys_win32.c b/code/sys/sys_win32.c index e740bcd6..d67c0716 100644 --- a/code/sys/sys_win32.c +++ b/code/sys/sys_win32.c @@ -424,6 +424,25 @@ char *Sys_Cwd( void ) { return cwd; } +/* +============== +Sys_BinaryPathRelative +============== +*/ +char *Sys_BinaryPathRelative(const char *relative) +{ + static char resolved[MAX_OSPATH]; + char combined[MAX_OSPATH]; + + snprintf(combined, sizeof(combined), "%s\\%s", Sys_BinaryPath(), relative); + + DWORD len = GetFullPathNameA(combined, MAX_OSPATH, resolved, NULL); + if (len == 0 || len >= MAX_OSPATH) + return NULL; + + return resolved; +} + /* ==============================================================