Mercurial > sdl-ios-xcode
annotate src/cdrom/linux/SDL_syscdrom.c @ 139:ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 09 Aug 2001 05:34:17 +0000 |
parents | 74212992fb08 |
children | b0f09f86378d |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Functions for system-level CD-ROM audio control */ | |
29 | |
30 #include <sys/types.h> | |
31 #include <stdlib.h> | |
32 #include <sys/stat.h> | |
33 #include <sys/ioctl.h> | |
34 #include <fcntl.h> | |
35 #include <stdio.h> | |
36 #include <string.h> | |
37 #include <errno.h> | |
38 #include <unistd.h> | |
39 #ifdef __linux__ | |
40 #include <linux/cdrom.h> | |
41 #endif | |
42 #ifdef __SVR4 | |
43 #include <sys/cdio.h> | |
44 #endif | |
45 | |
46 /* Define this to use the alternative getmntent() code */ | |
47 #ifndef __SVR4 | |
48 #define USE_MNTENT | |
49 #endif | |
50 | |
51 #ifdef USE_MNTENT | |
52 #if defined(__USLC__) | |
53 #include <sys/mntent.h> | |
54 #else | |
55 #include <mntent.h> | |
56 #endif | |
57 | |
58 #ifndef _PATH_MNTTAB | |
59 #ifdef MNTTAB | |
60 #define _PATH_MNTTAB MNTTAB | |
61 #else | |
62 #define _PATH_MNTTAB "/etc/fstab" | |
63 #endif | |
64 #endif /* !_PATH_MNTTAB */ | |
65 | |
66 #ifndef _PATH_MOUNTED | |
67 #define _PATH_MOUNTED "/etc/mtab" | |
68 #endif /* !_PATH_MOUNTED */ | |
69 | |
70 #ifndef MNTTYPE_CDROM | |
71 #define MNTTYPE_CDROM "iso9660" | |
72 #endif | |
73 #ifndef MNTTYPE_SUPER | |
74 #define MNTTYPE_SUPER "supermount" | |
75 #endif | |
76 #endif /* USE_MNTENT */ | |
77 | |
78 #include "SDL_error.h" | |
79 #include "SDL_cdrom.h" | |
80 #include "SDL_syscdrom.h" | |
81 | |
82 | |
83 /* The maximum number of CD-ROM drives we'll detect */ | |
84 #define MAX_DRIVES 16 | |
85 | |
86 /* A list of available CD-ROM drives */ | |
87 static char *SDL_cdlist[MAX_DRIVES]; | |
88 static dev_t SDL_cdmode[MAX_DRIVES]; | |
89 | |
90 /* The system-dependent CD control functions */ | |
91 static const char *SDL_SYS_CDName(int drive); | |
92 static int SDL_SYS_CDOpen(int drive); | |
93 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
94 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
95 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
96 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
97 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
98 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
99 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
100 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
101 | |
102 /* Some ioctl() errno values which occur when the tray is empty */ | |
103 #define ERRNO_TRAYEMPTY(errno) \ | |
104 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL)) | |
105 | |
106 /* Check a drive to see if it is a CD-ROM */ | |
107 static int CheckDrive(char *drive, char *mnttype, struct stat *stbuf) | |
108 { | |
109 int is_cd, cdfd; | |
110 struct cdrom_subchnl info; | |
111 | |
112 /* If it doesn't exist, return -1 */ | |
113 if ( stat(drive, stbuf) < 0 ) { | |
114 return(-1); | |
115 } | |
116 | |
117 /* If it does exist, verify that it's an available CD-ROM */ | |
118 is_cd = 0; | |
119 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { | |
120 cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); | |
121 if ( cdfd >= 0 ) { | |
122 info.cdsc_format = CDROM_MSF; | |
123 /* Under Linux, EIO occurs when a disk is not present. | |
124 */ | |
125 if ( (ioctl(cdfd, CDROMSUBCHNL, &info) == 0) || | |
126 ERRNO_TRAYEMPTY(errno) ) { | |
127 is_cd = 1; | |
128 } | |
129 close(cdfd); | |
130 } | |
131 #ifdef USE_MNTENT | |
132 /* Even if we can't read it, it might be mounted */ | |
133 else if ( mnttype && (strcmp(mnttype, MNTTYPE_CDROM) == 0) ) { | |
134 is_cd = 1; | |
135 } | |
136 #endif | |
137 } | |
138 return(is_cd); | |
139 } | |
140 | |
141 /* Add a CD-ROM drive to our list of valid drives */ | |
142 static void AddDrive(char *drive, struct stat *stbuf) | |
143 { | |
144 int i; | |
145 | |
146 if ( SDL_numcds < MAX_DRIVES ) { | |
147 /* Check to make sure it's not already in our list. | |
148 This can happen when we see a drive via symbolic link. | |
149 */ | |
150 for ( i=0; i<SDL_numcds; ++i ) { | |
151 if ( stbuf->st_rdev == SDL_cdmode[i] ) { | |
152 #ifdef DEBUG_CDROM | |
153 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); | |
154 #endif | |
155 return; | |
156 } | |
157 } | |
158 | |
159 /* Add this drive to our list */ | |
160 i = SDL_numcds; | |
161 SDL_cdlist[i] = (char *)malloc(strlen(drive)+1); | |
162 if ( SDL_cdlist[i] == NULL ) { | |
163 SDL_OutOfMemory(); | |
164 return; | |
165 } | |
166 strcpy(SDL_cdlist[i], drive); | |
167 SDL_cdmode[i] = stbuf->st_rdev; | |
168 ++SDL_numcds; | |
169 #ifdef DEBUG_CDROM | |
170 fprintf(stderr, "Added CD-ROM drive: %s\n", drive); | |
171 #endif | |
172 } | |
173 } | |
174 | |
175 #ifdef USE_MNTENT | |
176 static void CheckMounts(const char *mtab) | |
177 { | |
178 FILE *mntfp; | |
179 struct mntent *mntent; | |
180 struct stat stbuf; | |
181 | |
182 mntfp = setmntent(mtab, "r"); | |
183 if ( mntfp != NULL ) { | |
139
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
184 char *tmp; |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
185 char *mnt_type; |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
186 char *mnt_dev; |
0 | 187 |
188 while ( (mntent=getmntent(mntfp)) != NULL ) { | |
139
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
189 mnt_type = malloc(strlen(mntent->mnt_type) + 1); |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
190 if (mnt_type == NULL) |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
191 continue; /* maybe you'll get lucky next time. */ |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
192 |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
193 mnt_dev = malloc(strlen(mntent->mnt_fsname) + 1); |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
194 if (mnt_dev == NULL) { |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
195 free(mnt_type); |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
196 continue; |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
197 } |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
198 |
0 | 199 strcpy(mnt_type, mntent->mnt_type); |
200 strcpy(mnt_dev, mntent->mnt_fsname); | |
201 | |
202 /* Handle "supermount" filesystem mounts */ | |
203 if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { | |
204 tmp = strstr(mntent->mnt_opts, "fs="); | |
205 if ( tmp ) { | |
206 strcpy(mnt_type, tmp+strlen("fs=")); | |
207 tmp = strchr(mnt_type, ','); | |
208 if ( tmp ) { | |
209 *tmp = '\0'; | |
210 } | |
211 } | |
212 tmp = strstr(mntent->mnt_opts, "dev="); | |
213 if ( tmp ) { | |
214 strcpy(mnt_dev, tmp+strlen("dev=")); | |
215 tmp = strchr(mnt_dev, ','); | |
216 if ( tmp ) { | |
217 *tmp = '\0'; | |
218 } | |
219 } | |
220 } | |
221 if ( strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { | |
222 #ifdef DEBUG_CDROM | |
223 fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n", | |
224 mtab, mnt_dev, mntent->mnt_dir, mnt_type); | |
225 #endif | |
226 if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) { | |
227 AddDrive(mnt_dev, &stbuf); | |
228 } | |
229 } | |
139
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
230 free(mnt_dev); |
ef23a1bf1244
Fixed potential buffer overflow in Linux CD code (thanks Ryan!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
231 free(mnt_type); |
0 | 232 } |
233 endmntent(mntfp); | |
234 } | |
235 } | |
236 #endif /* USE_MNTENT */ | |
237 | |
238 int SDL_SYS_CDInit(void) | |
239 { | |
240 /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ | |
241 static char *checklist[] = { | |
242 "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL | |
243 }; | |
244 char *SDLcdrom; | |
245 int i, j, exists; | |
246 char drive[32]; | |
247 struct stat stbuf; | |
248 | |
249 /* Fill in our driver capabilities */ | |
250 SDL_CDcaps.Name = SDL_SYS_CDName; | |
251 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
252 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
253 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
254 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
255 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
256 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
257 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
258 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
259 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
260 | |
261 /* Look in the environment for our CD-ROM drive list */ | |
262 SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ | |
263 if ( SDLcdrom != NULL ) { | |
264 char *cdpath, *delim; | |
265 cdpath = malloc(strlen(SDLcdrom)+1); | |
266 if ( cdpath != NULL ) { | |
267 strcpy(cdpath, SDLcdrom); | |
268 SDLcdrom = cdpath; | |
269 do { | |
270 delim = strchr(SDLcdrom, ':'); | |
271 if ( delim ) { | |
272 *delim++ = '\0'; | |
273 } | |
274 #ifdef DEBUG_CDROM | |
275 fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); | |
276 #endif | |
277 if ( CheckDrive(SDLcdrom, NULL, &stbuf) > 0 ) { | |
278 AddDrive(SDLcdrom, &stbuf); | |
279 } | |
280 if ( delim ) { | |
281 SDLcdrom = delim; | |
282 } else { | |
283 SDLcdrom = NULL; | |
284 } | |
285 } while ( SDLcdrom ); | |
286 free(cdpath); | |
287 } | |
288 | |
289 /* If we found our drives, there's nothing left to do */ | |
290 if ( SDL_numcds > 0 ) { | |
291 return(0); | |
292 } | |
293 } | |
294 | |
295 #ifdef USE_MNTENT | |
296 /* Check /dev/cdrom first :-) */ | |
297 if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { | |
298 AddDrive("/dev/cdrom", &stbuf); | |
299 } | |
300 | |
301 /* Now check the currently mounted CD drives */ | |
302 CheckMounts(_PATH_MOUNTED); | |
303 | |
304 /* Finally check possible mountable drives in /etc/fstab */ | |
305 CheckMounts(_PATH_MNTTAB); | |
306 | |
307 /* If we found our drives, there's nothing left to do */ | |
308 if ( SDL_numcds > 0 ) { | |
309 return(0); | |
310 } | |
311 #endif /* USE_MNTENT */ | |
312 | |
313 /* Scan the system for CD-ROM drives. | |
314 Not always 100% reliable, so use the USE_MNTENT code above first. | |
315 */ | |
316 for ( i=0; checklist[i]; ++i ) { | |
317 if ( checklist[i][0] == '?' ) { | |
318 char *insert; | |
319 exists = 1; | |
320 for ( j=checklist[i][1]; exists; ++j ) { | |
321 sprintf(drive, "/dev/%s", &checklist[i][3]); | |
322 insert = strchr(drive, '?'); | |
323 if ( insert != NULL ) { | |
324 *insert = j; | |
325 } | |
326 #ifdef DEBUG_CDROM | |
327 fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); | |
328 #endif | |
329 switch (CheckDrive(drive, NULL, &stbuf)) { | |
330 /* Drive exists and is a CD-ROM */ | |
331 case 1: | |
332 AddDrive(drive, &stbuf); | |
333 break; | |
334 /* Drive exists, but isn't a CD-ROM */ | |
335 case 0: | |
336 break; | |
337 /* Drive doesn't exist */ | |
338 case -1: | |
339 exists = 0; | |
340 break; | |
341 } | |
342 } | |
343 } else { | |
344 sprintf(drive, "/dev/%s", checklist[i]); | |
345 #ifdef DEBUG_CDROM | |
346 fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); | |
347 #endif | |
348 if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { | |
349 AddDrive(drive, &stbuf); | |
350 } | |
351 } | |
352 } | |
353 return(0); | |
354 } | |
355 | |
356 /* General ioctl() CD-ROM command function */ | |
357 static int SDL_SYS_CDioctl(int id, int command, void *arg) | |
358 { | |
359 int retval; | |
360 | |
361 retval = ioctl(id, command, arg); | |
362 if ( retval < 0 ) { | |
363 SDL_SetError("ioctl() error: %s", strerror(errno)); | |
364 } | |
365 return(retval); | |
366 } | |
367 | |
368 static const char *SDL_SYS_CDName(int drive) | |
369 { | |
370 return(SDL_cdlist[drive]); | |
371 } | |
372 | |
373 static int SDL_SYS_CDOpen(int drive) | |
374 { | |
375 return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0)); | |
376 } | |
377 | |
378 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
379 { | |
380 struct cdrom_tochdr toc; | |
381 int i, okay; | |
382 struct cdrom_tocentry entry; | |
383 | |
384 okay = 0; | |
385 if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0 ) { | |
386 cdrom->numtracks = toc.cdth_trk1-toc.cdth_trk0+1; | |
387 if ( cdrom->numtracks > SDL_MAX_TRACKS ) { | |
388 cdrom->numtracks = SDL_MAX_TRACKS; | |
389 } | |
390 /* Read all the track TOC entries */ | |
391 for ( i=0; i<=cdrom->numtracks; ++i ) { | |
392 if ( i == cdrom->numtracks ) { | |
393 cdrom->track[i].id = CDROM_LEADOUT; | |
394 } else { | |
395 cdrom->track[i].id = toc.cdth_trk0+i; | |
396 } | |
397 entry.cdte_track = cdrom->track[i].id; | |
398 entry.cdte_format = CDROM_MSF; | |
399 if ( SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, | |
400 &entry) < 0 ) { | |
401 break; | |
402 } else { | |
403 if ( entry.cdte_ctrl & CDROM_DATA_TRACK ) { | |
404 cdrom->track[i].type = SDL_DATA_TRACK; | |
405 } else { | |
406 cdrom->track[i].type = SDL_AUDIO_TRACK; | |
407 } | |
408 cdrom->track[i].offset = MSF_TO_FRAMES( | |
409 entry.cdte_addr.msf.minute, | |
410 entry.cdte_addr.msf.second, | |
411 entry.cdte_addr.msf.frame); | |
412 cdrom->track[i].length = 0; | |
413 if ( i > 0 ) { | |
414 cdrom->track[i-1].length = | |
415 cdrom->track[i].offset- | |
416 cdrom->track[i-1].offset; | |
417 } | |
418 } | |
419 } | |
420 if ( i == (cdrom->numtracks+1) ) { | |
421 okay = 1; | |
422 } | |
423 } | |
424 return(okay ? 0 : -1); | |
425 } | |
426 | |
427 /* Get CD-ROM status */ | |
428 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
429 { | |
430 CDstatus status; | |
431 struct cdrom_tochdr toc; | |
432 struct cdrom_subchnl info; | |
433 | |
434 info.cdsc_format = CDROM_MSF; | |
435 if ( ioctl(cdrom->id, CDROMSUBCHNL, &info) < 0 ) { | |
436 if ( ERRNO_TRAYEMPTY(errno) ) { | |
437 status = CD_TRAYEMPTY; | |
438 } else { | |
439 status = CD_ERROR; | |
440 } | |
441 } else { | |
442 switch (info.cdsc_audiostatus) { | |
443 case CDROM_AUDIO_INVALID: | |
444 case CDROM_AUDIO_NO_STATUS: | |
445 /* Try to determine if there's a CD available */ | |
446 if (ioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) | |
447 status = CD_STOPPED; | |
448 else | |
449 status = CD_TRAYEMPTY; | |
450 break; | |
451 case CDROM_AUDIO_COMPLETED: | |
452 status = CD_STOPPED; | |
453 break; | |
454 case CDROM_AUDIO_PLAY: | |
455 status = CD_PLAYING; | |
456 break; | |
457 case CDROM_AUDIO_PAUSED: | |
458 /* Workaround buggy CD-ROM drive */ | |
459 if ( info.cdsc_trk == CDROM_LEADOUT ) { | |
460 status = CD_STOPPED; | |
461 } else { | |
462 status = CD_PAUSED; | |
463 } | |
464 break; | |
465 default: | |
466 status = CD_ERROR; | |
467 break; | |
468 } | |
469 } | |
470 if ( position ) { | |
471 if ( status == CD_PLAYING || (status == CD_PAUSED) ) { | |
472 *position = MSF_TO_FRAMES( | |
473 info.cdsc_absaddr.msf.minute, | |
474 info.cdsc_absaddr.msf.second, | |
475 info.cdsc_absaddr.msf.frame); | |
476 } else { | |
477 *position = 0; | |
478 } | |
479 } | |
480 return(status); | |
481 } | |
482 | |
483 /* Start play */ | |
484 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
485 { | |
486 struct cdrom_msf playtime; | |
487 | |
488 FRAMES_TO_MSF(start, | |
489 &playtime.cdmsf_min0, &playtime.cdmsf_sec0, &playtime.cdmsf_frame0); | |
490 FRAMES_TO_MSF(start+length, | |
491 &playtime.cdmsf_min1, &playtime.cdmsf_sec1, &playtime.cdmsf_frame1); | |
492 #ifdef DEBUG_CDROM | |
493 fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n", | |
494 playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0, | |
495 playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1); | |
496 #endif | |
497 return(SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime)); | |
498 } | |
499 | |
500 /* Pause play */ | |
501 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
502 { | |
503 return(SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0)); | |
504 } | |
505 | |
506 /* Resume play */ | |
507 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
508 { | |
509 return(SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0)); | |
510 } | |
511 | |
512 /* Stop play */ | |
513 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
514 { | |
515 return(SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0)); | |
516 } | |
517 | |
518 /* Eject the CD-ROM */ | |
519 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
520 { | |
521 return(SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0)); | |
522 } | |
523 | |
524 /* Close the CD-ROM handle */ | |
525 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
526 { | |
527 close(cdrom->id); | |
528 } | |
529 | |
530 void SDL_SYS_CDQuit(void) | |
531 { | |
532 int i; | |
533 | |
534 if ( SDL_numcds > 0 ) { | |
535 for ( i=0; i<SDL_numcds; ++i ) { | |
536 free(SDL_cdlist[i]); | |
537 } | |
538 SDL_numcds = 0; | |
539 } | |
540 } | |
541 |