19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef SDL_CDROM_OPENBSD
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Functions for system-level CD-ROM audio control */
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/types.h>
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/ioctl.h>
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/stat.h>
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <fcntl.h>
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <errno.h>
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <unistd.h>
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/ioctl.h>
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <sys/cdio.h>
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_cdrom.h"
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_syscdrom.h"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The maximum number of CD-ROM drives we'll detect */
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MAX_DRIVES	16
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* A list of available CD-ROM drives */
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *SDL_cdlist[MAX_DRIVES];
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic dev_t SDL_cdmode[MAX_DRIVES];
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The system-dependent CD control functions */
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const char *SDL_SYS_CDName(int drive);
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDOpen(int drive);
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPause(SDL_CD *cdrom);
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDResume(SDL_CD *cdrom);
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDStop(SDL_CD *cdrom);
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDEject(SDL_CD *cdrom);
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_SYS_CDClose(SDL_CD *cdrom);
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Some ioctl() errno values which occur when the tray is empty */
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define ERRNO_TRAYEMPTY(errno)	\
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	((errno == EIO) || (errno == ENOENT) || (errno == EINVAL) || \
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 (errno == ENODEV))
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Check a drive to see if it is a CD-ROM */
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int CheckDrive(char *drive, struct stat *stbuf)
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int is_cd, cdfd;
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_read_subchannel info;
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* If it doesn't exist, return -1 */
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( stat(drive, stbuf) < 0 ) {
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* If it does exist, verify that it's an available CD-ROM */
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	is_cd = 0;
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( cdfd >= 0 ) {
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			info.address_format = CD_MSF_FORMAT;
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			info.data_format = CD_CURRENT_POSITION;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			info.data_len = 0;
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			info.data = NULL;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			/* Under Linux, EIO occurs when a disk is not present.
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			   This isn't 100% reliable, so we use the USE_MNTENT
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			   code above instead.
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			 */
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						ERRNO_TRAYEMPTY(errno) ) {
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				is_cd = 1;
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			close(cdfd);
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		else if (ERRNO_TRAYEMPTY(errno))
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			is_cd = 1;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(is_cd);
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Add a CD-ROM drive to our list of valid drives */
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void AddDrive(char *drive, struct stat *stbuf)
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i;
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_numcds < MAX_DRIVES ) {
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Check to make sure it's not already in our list.
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 	   This can happen when we see a drive via symbolic link.
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		 */
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( i=0; i<SDL_numcds; ++i ) {
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( stbuf->st_rdev == SDL_cdmode[i] ) {
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_CDROM
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				return;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Add this drive to our list */
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		i = SDL_numcds;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_cdlist[i] = SDL_strdup(drive);
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( SDL_cdlist[i] == NULL ) {
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_OutOfMemory();
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return;
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_cdmode[i] = stbuf->st_rdev;
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		++SDL_numcds;
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_CDROM
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint  SDL_SYS_CDInit(void)
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	static char *checklist[] = {
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__OPENBSD__)
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		"?0 cd?c", "cdrom", NULL
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#elif defined(__NETBSD__)
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		"?0 cd?d", "?0 cd?c", "cdrom", NULL
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		"?0 cd?c", "?0 acd?c", "cdrom", NULL
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	};
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char *SDLcdrom;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i, j, exists;
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char drive[32];
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct stat stbuf;
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Fill in our driver capabilities */
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Name = SDL_SYS_CDName;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Open = SDL_SYS_CDOpen;
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Status = SDL_SYS_CDStatus;
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Play = SDL_SYS_CDPlay;
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Pause = SDL_SYS_CDPause;
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Resume = SDL_SYS_CDResume;
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Stop = SDL_SYS_CDStop;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Eject = SDL_SYS_CDEject;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CDcaps.Close = SDL_SYS_CDClose;
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Look in the environment for our CD-ROM drive list */
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDLcdrom != NULL ) {
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		char *cdpath, *delim;
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		size_t len = SDL_strlen(SDLcdrom)+1;
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		cdpath = SDL_stack_alloc(char, len);
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( cdpath != NULL ) {
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_strlcpy(cdpath, SDLcdrom, len);
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDLcdrom = cdpath;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			do {
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				delim = SDL_strchr(SDLcdrom, ':');
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( delim ) {
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					*delim++ = '\0';
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					AddDrive(SDLcdrom, &stbuf);
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( delim ) {
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					SDLcdrom = delim;
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				} else {
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					SDLcdrom = NULL;
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} while ( SDLcdrom );
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_stack_free(cdpath);
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* If we found our drives, there's nothing left to do */
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( SDL_numcds > 0 ) {
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return(0);
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Scan the system for CD-ROM drives */
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for ( i=0; checklist[i]; ++i ) {
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( checklist[i][0] == '?' ) {
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			char *insert;
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			exists = 1;
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			for ( j=checklist[i][1]; exists; ++j ) {
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]);
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				insert = SDL_strchr(drive, '?');
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( insert != NULL ) {
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					*insert = j;
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				switch (CheckDrive(drive, &stbuf)) {
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					/* Drive exists and is a CD-ROM */
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case 1:
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						AddDrive(drive, &stbuf);
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						break;
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					/* Drive exists, but isn't a CD-ROM */
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case 0:
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						break;
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					/* Drive doesn't exist */
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					case -1:
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						exists = 0;
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						break;
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( CheckDrive(drive, &stbuf) > 0 ) {
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				AddDrive(drive, &stbuf);
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* General ioctl() CD-ROM command function */
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDioctl(int id, int command, void *arg)
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int retval;
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retval = ioctl(id, command, arg);
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( retval < 0 ) {
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_SetError("ioctl() error: %s", strerror(errno));
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(retval);
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic const char *SDL_SYS_CDName(int drive)
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_cdlist[drive]);
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDOpen(int drive)
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(open(SDL_cdlist[drive], (O_RDONLY|O_EXCL|O_NONBLOCK), 0));
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_toc_header toc;
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i, okay;
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_read_toc_entry entry;
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct cd_toc_entry data;
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	okay = 0;
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0 ) {
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		cdrom->numtracks = toc.ending_track-toc.starting_track+1;
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			cdrom->numtracks = SDL_MAX_TRACKS;
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Read all the track TOC entries */
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( i=0; i<=cdrom->numtracks; ++i ) {
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( i == cdrom->numtracks ) {
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				cdrom->track[i].id = 0xAA; /* CDROM_LEADOUT */
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} else {
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				cdrom->track[i].id = toc.starting_track+i;
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			entry.starting_track = cdrom->track[i].id;
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			entry.address_format = CD_MSF_FORMAT;
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			entry.data_len = sizeof(data);
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			entry.data = &data;
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS,
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall								&entry) < 0 ) {
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			} else {
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				cdrom->track[i].type = data.control;
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				cdrom->track[i].offset = MSF_TO_FRAMES(
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						data.addr.msf.minute,
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						data.addr.msf.second,
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						data.addr.msf.frame);
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				cdrom->track[i].length = 0;
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if ( i > 0 ) {
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					cdrom->track[i-1].length =
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						cdrom->track[i].offset-
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						cdrom->track[i-1].offset;
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				}
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( i == (cdrom->numtracks+1) ) {
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			okay = 1;
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(okay ? 0 : -1);
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Get CD-ROM status */
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	CDstatus status;
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_toc_header toc;
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_read_subchannel info;
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct cd_sub_channel_info data;
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info.address_format = CD_MSF_FORMAT;
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info.data_format = CD_CURRENT_POSITION;
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info.track = 0;
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info.data_len = sizeof(data);
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info.data = &data;
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) {
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( ERRNO_TRAYEMPTY(errno) ) {
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			status = CD_TRAYEMPTY;
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			status = CD_ERROR;
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		switch (data.header.audio_status) {
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case CD_AS_AUDIO_INVALID:
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case CD_AS_NO_STATUS:
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				/* Try to determine if there's a CD available */
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0)
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					status = CD_STOPPED;
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				else
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					status = CD_TRAYEMPTY;
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case CD_AS_PLAY_COMPLETED:
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				status = CD_STOPPED;
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case CD_AS_PLAY_IN_PROGRESS:
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				status = CD_PLAYING;
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			case CD_AS_PLAY_PAUSED:
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				status = CD_PAUSED;
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			default:
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				status = CD_ERROR;
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( position ) {
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( status == CD_PLAYING || (status == CD_PAUSED) ) {
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			*position = MSF_TO_FRAMES(
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					data.what.position.absaddr.msf.minute,
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					data.what.position.absaddr.msf.second,
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					data.what.position.absaddr.msf.frame);
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			*position = 0;
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(status);
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Start play */
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	struct ioc_play_msf playtime;
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	FRAMES_TO_MSF(start,
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		&playtime.start_m, &playtime.start_s, &playtime.start_f);
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	FRAMES_TO_MSF(start+length,
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		&playtime.end_m, &playtime.end_s, &playtime.end_f);
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef DEBUG_CDROM
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	playtime.start_m, playtime.start_s, playtime.start_f,
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	playtime.end_m, playtime.end_s, playtime.end_f);
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ioctl(cdrom->id, CDIOCSTART, 0);
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime));
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Pause play */
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDPause(SDL_CD *cdrom)
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0));
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Resume play */
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDResume(SDL_CD *cdrom)
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0));
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Stop play */
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDStop(SDL_CD *cdrom)
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0));
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Eject the CD-ROM */
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int SDL_SYS_CDEject(SDL_CD *cdrom)
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_SYS_CDioctl(cdrom->id, CDIOCALLOW, 0);
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0));
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Close the CD-ROM handle */
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void SDL_SYS_CDClose(SDL_CD *cdrom)
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	close(cdrom->id);
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_SYS_CDQuit(void)
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int i;
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_numcds > 0 ) {
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( i=0; i<SDL_numcds; ++i ) {
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_free(SDL_cdlist[i]);
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_numcds = 0;
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* SDL_CDROM_OPENBSD */
417