src/cdrom/osf/SDL_syscdrom.c
changeset 1019 e3b3130f3af8
parent 874 9719e7f51a3a
child 1336 3692456e7b0f
     1.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Mon Dec 27 20:03:53 2004 +0000
     1.2 +++ b/src/cdrom/osf/SDL_syscdrom.c	Sun Jan 02 05:05:21 2005 +0000
     1.3 @@ -22,9 +22,10 @@
     1.4  
     1.5  /* Functions for system-level CD-ROM audio control */
     1.6  
     1.7 -//#define DEBUG_CDROM 1
     1.8 +/* #define DEBUG_CDROM 1 */
     1.9  
    1.10  #include <sys/types.h>
    1.11 +#include <dirent.h>
    1.12  #include <sys/stat.h>
    1.13  #include <fcntl.h>
    1.14  #include <io/cam/cdrom.h>
    1.15 @@ -141,11 +142,22 @@
    1.16  
    1.17  int  SDL_SYS_CDInit(void)
    1.18  {
    1.19 -    /* checklist: /dev/rdisk/cdrom?c
    1.20 +    /* checklist:
    1.21 +     *
    1.22 +     * Tru64 5.X (/dev/rdisk/cdrom?c)
    1.23 +     * dir: /dev/rdisk, name: cdrom
    1.24 +     *
    1.25 +     * Digital UNIX 4.0X (/dev/rrz?c)
    1.26 +     * dir: /dev, name: rrz
    1.27       *
    1.28       */
    1.29 -    static char *checklist[] = {
    1.30 -	"?0 rdisk/cdrom?",NULL};
    1.31 +    struct {
    1.32 +	char *dir;
    1.33 +	char *name;
    1.34 +    } checklist[] = {
    1.35 +	{"/dev/rdisk", "cdrom"},
    1.36 +	{"/dev", "rrz"},
    1.37 +	{NULL, NULL}};
    1.38      char drive[32];
    1.39      char *SDLcdrom;
    1.40      int i, j, exists;
    1.41 @@ -195,37 +207,32 @@
    1.42  	}
    1.43      }
    1.44      /* Scan the system for CD-ROM drives */
    1.45 -    for ( i=0; checklist[i]; ++i ) {
    1.46 -	if ( checklist[i][0] == '?' ) {
    1.47 -	    char *insert;
    1.48 -	    exists = 1;
    1.49 -	    for ( j=checklist[i][1]; exists; ++j ) {
    1.50 -		sprintf(drive, "/dev/%sc", &checklist[i][3]);
    1.51 -		insert = strchr(drive, '?');
    1.52 -		if ( insert != NULL ) {
    1.53 -		    *insert = j;
    1.54 -		}
    1.55 -		switch (CheckDrive(drive, &stbuf)) {
    1.56 -		    /* Drive exists and is a CD-ROM */
    1.57 -		    case 1:
    1.58 -			AddDrive(drive, &stbuf);
    1.59 -			break;
    1.60 -			/* Drive exists, but isn't a CD-ROM */
    1.61 -		    case 0:
    1.62 -			break;
    1.63 -			/* Drive doesn't exist */
    1.64 -		    case -1:
    1.65 -			exists = 0;
    1.66 -			break;
    1.67 -		}
    1.68 -	    }
    1.69 +    for ( i = 0; checklist[i].dir; ++i) {
    1.70 +	DIR *devdir;
    1.71 +	struct dirent *devent;
    1.72 +	int name_len;
    1.73 +
    1.74 +	devdir = opendir(checklist[i].dir);
    1.75 +	if (devdir) {
    1.76 +	    name_len = strlen(checklist[i].name);
    1.77 +	    while (devent = readdir(devdir))
    1.78 +		if (memcmp(checklist[i].name, devent->d_name, name_len) == 0)
    1.79 +		    if (devent->d_name[devent->d_namlen-1] == 'c') {
    1.80 +			sprintf(drive, "%s/%s", checklist[i].dir, devent->d_name);
    1.81 +#ifdef DEBUG_CDROM
    1.82 +			fprintf(stderr, "Try to add drive: %s\n", drive);
    1.83 +#endif
    1.84 +			if ( CheckDrive(drive, &stbuf) > 0 )
    1.85 +			    AddDrive(drive, &stbuf);
    1.86 +		    }
    1.87 +	    closedir(devdir);
    1.88  	} else {
    1.89 -	    sprintf(drive, "/dev/%s", checklist[i]);
    1.90 -	    if ( CheckDrive(drive, &stbuf) > 0 ) {
    1.91 -		AddDrive(drive, &stbuf);
    1.92 -	    }
    1.93 +#ifdef DEBUG_CDROM
    1.94 +	    fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir);
    1.95 +#endif
    1.96  	}
    1.97      }
    1.98 +
    1.99  /*
   1.100      SDLcdrom=malloc(sizeof(char) * 32);
   1.101      strcpy(SDLcdrom,"/dev/rdisk/cdrom0c");