Removed use of atexit()
authorSam Lantinga <slouken@libsdl.org>
Sun, 14 May 2006 21:07:27 +0000
changeset 321a72a7f07c8f1
parent 320 3ea536c90a50
child 322 54d96d95a0cb
Removed use of atexit()
playmus.c
playwave.c
     1.1 --- a/playmus.c	Sun May 14 05:33:39 2006 +0000
     1.2 +++ b/playmus.c	Sun May 14 21:07:27 2006 +0000
     1.3 @@ -38,7 +38,7 @@
     1.4  static Mix_Music *music = NULL;
     1.5  static int next_track = 0;
     1.6  
     1.7 -void CleanUp(void)
     1.8 +void CleanUp(int exitcode)
     1.9  {
    1.10  	if( Mix_PlayingMusic() ) {
    1.11  		Mix_FadeOutMusic(1500);
    1.12 @@ -53,6 +53,7 @@
    1.13  		audio_open = 0;
    1.14  	}
    1.15  	SDL_Quit();
    1.16 +	exit(exitcode);
    1.17  }
    1.18  
    1.19  void Usage(char *argv0)
    1.20 @@ -158,9 +159,8 @@
    1.21  		return(255);
    1.22  	}
    1.23  
    1.24 -	atexit(CleanUp);
    1.25  	signal(SIGINT, IntHandler);
    1.26 -	signal(SIGTERM, exit);
    1.27 +	signal(SIGTERM, CleanUp);
    1.28  
    1.29  	/* Open the audio device */
    1.30  	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
    1.31 @@ -195,7 +195,7 @@
    1.32  		if ( music == NULL ) {
    1.33  			fprintf(stderr, "Couldn't load %s: %s\n",
    1.34  				argv[i], SDL_GetError());
    1.35 -			return(2);
    1.36 +			CleanUp(2);
    1.37  		}
    1.38  		
    1.39  		/* Play and then exit */
    1.40 @@ -219,5 +219,8 @@
    1.41  		
    1.42  		i++;
    1.43  	}
    1.44 -	return(0);
    1.45 +	CleanUp(0);
    1.46 +
    1.47 +	/* Not reached, but fixes compiler warnings */
    1.48 +	return 0;
    1.49  }
     2.1 --- a/playwave.c	Sun May 14 05:33:39 2006 +0000
     2.2 +++ b/playwave.c	Sun May 14 21:07:27 2006 +0000
     2.3 @@ -250,7 +250,7 @@
     2.4  #endif
     2.5  
     2.6  
     2.7 -static void CleanUp(void)
     2.8 +static void CleanUp(int exitcode)
     2.9  {
    2.10  	if ( wave ) {
    2.11  		Mix_FreeChunk(wave);
    2.12 @@ -261,6 +261,8 @@
    2.13  		audio_open = 0;
    2.14  	}
    2.15  	SDL_Quit();
    2.16 +
    2.17 +	exit(exitcode);
    2.18  }
    2.19  
    2.20  
    2.21 @@ -390,14 +392,13 @@
    2.22  		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    2.23  		return(255);
    2.24  	}
    2.25 -	atexit(CleanUp);
    2.26 -	signal(SIGINT, exit);
    2.27 -	signal(SIGTERM, exit);
    2.28 +	signal(SIGINT, CleanUp);
    2.29 +	signal(SIGTERM, CleanUp);
    2.30  
    2.31  	/* Open the audio device */
    2.32  	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, 4096) < 0) {
    2.33  		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    2.34 -		return(2);
    2.35 +		CleanUp(2);
    2.36  	} else {
    2.37  		Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
    2.38  		printf("Opened audio at %d Hz %d bit %s", audio_rate,
    2.39 @@ -421,7 +422,7 @@
    2.40  	if ( wave == NULL ) {
    2.41  		fprintf(stderr, "Couldn't load %s: %s\n",
    2.42  						argv[i], SDL_GetError());
    2.43 -		return(2);
    2.44 +		CleanUp(2);
    2.45  	}
    2.46  
    2.47  	if (reverse_sample) {
    2.48 @@ -460,7 +461,10 @@
    2.49  
    2.50  	} /* while still_playing() loop... */
    2.51  
    2.52 -	return(0);
    2.53 +	CleanUp(0);
    2.54 +
    2.55 +	/* Not reached, but fixes compiler warnings */
    2.56 +	return 0;
    2.57  }
    2.58  
    2.59  /* end of playwave.c ... */