aboutsummaryrefslogtreecommitdiffstats
path: root/code/unix
diff options
context:
space:
mode:
authortma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-02-26 18:44:15 +0000
committertma <tma@edf5b092-35ff-0310-97b2-ce42778d08ea>2006-02-26 18:44:15 +0000
commit3cbb3f928dda70718ed5f4158f4b2254078301d8 (patch)
tree239d09d003642adc121f936dd6a2e2da7dbc6aed /code/unix
parent71a5742b26ac3bca97a64b7aa3dad376b802ed2d (diff)
downloadioquake3-aero-3cbb3f928dda70718ed5f4158f4b2254078301d8.tar.gz
ioquake3-aero-3cbb3f928dda70718ed5f4158f4b2254078301d8.zip
* Resolve symlinks to the binary. This prevents the situation where a symlink
to ioq3 in e.g. /usr/local/bin/ cannot locate the data files since it thinks /usr/local/bin/ is the directory the actual binary sits. git-svn-id: svn://svn.icculus.org/quake3/trunk@586 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code/unix')
-rw-r--r--code/unix/unix_main.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/code/unix/unix_main.c b/code/unix/unix_main.c
index 20a90a0..b60a326 100644
--- a/code/unix/unix_main.c
+++ b/code/unix/unix_main.c
@@ -1335,6 +1335,54 @@ void Sys_PrintBinVersion( const char* name ) {
fprintf( stdout, "%s\n\n", sep );
}
+/*
+=================
+Sys_BinName
+
+This resolves any symlinks to the binary. It's disabled for debug
+builds because there are situations where you are likely to want
+to symlink to binaries and /not/ have the links resolved.
+=================
+*/
+char *Sys_BinName( const char *arg0 )
+{
+#ifdef NDEBUG
+ int n;
+ char src[ PATH_MAX ];
+ char dir[ PATH_MAX ];
+ qboolean links = qfalse;
+#endif
+
+ static char dst[ PATH_MAX ];
+
+ Q_strncpyz( dst, arg0, PATH_MAX );
+
+#ifdef NDEBUG
+ while( ( n = readlink( dst, src, PATH_MAX ) ) >= 0 )
+ {
+ src[ n ] = '\0';
+
+ Q_strncpyz( dir, dirname( dst ), PATH_MAX );
+ Q_strncpyz( dst, dir, PATH_MAX );
+ Q_strcat( dst, PATH_MAX, "/" );
+ Q_strcat( dst, PATH_MAX, src );
+
+ links = qtrue;
+ }
+
+ if( links )
+ {
+ Q_strncpyz( dst, Sys_Cwd( ), PATH_MAX );
+ Q_strcat( dst, PATH_MAX, "/" );
+ Q_strcat( dst, PATH_MAX, dir );
+ Q_strcat( dst, PATH_MAX, "/" );
+ Q_strcat( dst, PATH_MAX, src );
+ }
+#endif
+
+ return dst;
+}
+
void Sys_ParseArgs( int argc, char* argv[] ) {
if ( argc==2 )
@@ -1342,7 +1390,7 @@ void Sys_ParseArgs( int argc, char* argv[] ) {
if ( (!strcmp( argv[1], "--version" ))
|| ( !strcmp( argv[1], "-v" )) )
{
- Sys_PrintBinVersion( argv[0] );
+ Sys_PrintBinVersion( Sys_BinName( argv[0] ) );
Sys_Exit(0);
}
}
@@ -1365,7 +1413,7 @@ int main ( int argc, char* argv[] )
Sys_ParseArgs( argc, argv ); // bk010104 - added this for support
- strncat(cdpath, argv[0], sizeof(cdpath)-1);
+ strncat(cdpath, Sys_BinName( argv[0] ), sizeof(cdpath)-1);
Sys_SetDefaultCDPath(dirname(cdpath));
Sys_SetDefaultInstallPath(DEFAULT_BASEDIR);