Mercurial > sdl-ios-xcode
comparison test/testcdrom.c @ 1151:be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
if SDL is built with a non-cdecl calling convention, and it's just generally
bad practice anyhow.
Now programs explicitly call SDL_Quit() where appropriate, wrap SDL_Quit() in
a cdecl function where it can't be avoided, and rely on the parachute where
a crash might have hit the atexit() before (these ARE test programs, after
all!).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 28 Sep 2005 11:36:20 +0000 |
parents | 9c6717a1c66f |
children | d93862a3d821 |
comparison
equal
deleted
inserted
replaced
1150:7d8e1925f35b | 1151:be9c9c8f6d53 |
---|---|
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <ctype.h> | 6 #include <ctype.h> |
7 | 7 |
8 #include "SDL.h" | 8 #include "SDL.h" |
9 | 9 |
10 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | |
11 static void quit(int rc) | |
12 { | |
13 SDL_Quit(); | |
14 exit(rc); | |
15 } | |
10 | 16 |
11 static void PrintStatus(int driveindex, SDL_CD *cdrom) | 17 static void PrintStatus(int driveindex, SDL_CD *cdrom) |
12 { | 18 { |
13 CDstatus status; | 19 CDstatus status; |
14 char *status_str; | 20 char *status_str; |
90 SDL_CD *cdrom; | 96 SDL_CD *cdrom; |
91 | 97 |
92 /* Initialize SDL first */ | 98 /* Initialize SDL first */ |
93 if ( SDL_Init(SDL_INIT_CDROM) < 0 ) { | 99 if ( SDL_Init(SDL_INIT_CDROM) < 0 ) { |
94 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 100 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
95 exit(1); | 101 return(1); |
96 } | 102 } |
97 atexit(SDL_Quit); | |
98 | 103 |
99 /* Find out how many CD-ROM drives are connected to the system */ | 104 /* Find out how many CD-ROM drives are connected to the system */ |
100 if ( SDL_CDNumDrives() == 0 ) { | 105 if ( SDL_CDNumDrives() == 0 ) { |
101 printf("No CD-ROM devices detected\n"); | 106 printf("No CD-ROM devices detected\n"); |
102 exit(0); | 107 quit(0); |
103 } | 108 } |
104 printf("Drives available: %d\n", SDL_CDNumDrives()); | 109 printf("Drives available: %d\n", SDL_CDNumDrives()); |
105 for ( i=0; i<SDL_CDNumDrives(); ++i ) { | 110 for ( i=0; i<SDL_CDNumDrives(); ++i ) { |
106 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i)); | 111 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i)); |
107 } | 112 } |
114 } | 119 } |
115 cdrom = SDL_CDOpen(drive); | 120 cdrom = SDL_CDOpen(drive); |
116 if ( cdrom == NULL ) { | 121 if ( cdrom == NULL ) { |
117 fprintf(stderr, "Couldn't open drive %d: %s\n", drive, | 122 fprintf(stderr, "Couldn't open drive %d: %s\n", drive, |
118 SDL_GetError()); | 123 SDL_GetError()); |
119 exit(2); | 124 quit(2); |
120 } | 125 } |
121 #ifdef TEST_NULLCD | 126 #ifdef TEST_NULLCD |
122 cdrom = NULL; | 127 cdrom = NULL; |
123 #endif | 128 #endif |
124 | 129 |
190 SDL_Delay(atoi(argv[++i])); | 195 SDL_Delay(atoi(argv[++i])); |
191 printf("Delayed %d milliseconds\n", atoi(argv[i])); | 196 printf("Delayed %d milliseconds\n", atoi(argv[i])); |
192 } else { | 197 } else { |
193 PrintUsage(argv[0]); | 198 PrintUsage(argv[0]); |
194 SDL_CDClose(cdrom); | 199 SDL_CDClose(cdrom); |
195 exit(1); | 200 quit(1); |
196 } | 201 } |
197 } | 202 } |
198 PrintStatus(drive, cdrom); | 203 PrintStatus(drive, cdrom); |
199 SDL_CDClose(cdrom); | 204 SDL_CDClose(cdrom); |
205 SDL_Quit(); | |
200 | 206 |
201 return(0); | 207 return(0); |
202 } | 208 } |