From 310effbb68b3e335574b682bb4359d8e29f3430b Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sun, 26 Feb 2006 19:21:34 +0000 Subject: * Merged ioq3-r587 - Symlink following stuff - Sound fixes --- src/client/snd_codec_ogg.c | 5 +++-- src/client/snd_openal.c | 16 ++++++++++++++ src/unix/unix_main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/client/snd_codec_ogg.c b/src/client/snd_codec_ogg.c index 464d8d38..9c17c0b9 100644 --- a/src/client/snd_codec_ogg.c +++ b/src/client/snd_codec_ogg.c @@ -412,7 +412,7 @@ where we read the whole stream at once. void *S_OGG_CodecLoad(const char *filename, snd_info_t *info) { snd_stream_t *stream; - unsigned char *buffer; + byte *buffer; int bytesRead; // check if input is valid @@ -452,8 +452,9 @@ void *S_OGG_CodecLoad(const char *filename, snd_info_t *info) // we don't even have read a single byte if(bytesRead <= 0) { + Z_Free(buffer); S_OGG_CodecCloseStream(stream); - + return NULL; } diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c index 699db246..fa1aaad0 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -1378,7 +1378,23 @@ void S_AL_StartBackgroundTrack( const char *intro, const char *loop ) // Queue the musicBuffers up for(i = 0; i < NUM_MUSIC_BUFFERS; i++) + { S_AL_MusicProcess(musicBuffers[i]); + + // check whether our stream still exists. + if(!mus_stream) + { + // there was an error in reading which resulted in a + // closed stream. We must bail out or we'll crash. + + // deallocate everything we allocated so far: + qalDeleteBuffers(NUM_MUSIC_BUFFERS, musicBuffers); + S_AL_MusicSourceFree(); + + return; + } + } + qalSourceQueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers); // Set the initial gain property diff --git a/src/unix/unix_main.c b/src/unix/unix_main.c index 6e9ead4a..c9b0a781 100644 --- a/src/unix/unix_main.c +++ b/src/unix/unix_main.c @@ -1336,6 +1336,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 ) @@ -1343,7 +1391,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); } } @@ -1366,7 +1414,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); -- cgit