home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / util / cdro / 003 / cdrom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-19  |  1.5 KB  |  68 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. /* Returns the cdrom drive letter on your system     */
  6. /* It uses calls to MSCDEX to determine drive letter */
  7.  
  8. char *findcdrom()
  9. {
  10.        union  REGS      inregs;
  11.        union  REGS      outregs;
  12.        static char    buf[3];
  13.  
  14.        inregs.x.ax = 0x1500;   /* Get Number of CDROM drive letters    */
  15.        inregs.x.bx = 0;        /* Init to zero                         */
  16.  
  17.        int86(0x2f, &inregs, &outregs);
  18.  
  19.        /* If no CDROM drives are found or MSCDEX not present return */
  20.        /* error messages                                            */
  21.  
  22.        if (outregs.x.bx == 0)
  23.        {
  24.            printf ("No cdrom drive found\n");
  25.            printf ("Use set CDROM=q: to assign drive letter anyway \n");
  26.            exit (1);
  27.        }
  28.  
  29.        /* If you have more than one drive use environment variable CDROM */
  30.        /* for the drive to use                         */
  31.  
  32.        if (outregs.x.bx > 1)
  33.        {
  34.         printf ("You have more than 1 cdrom drive in your system\n");
  35.         printf ("Use set CDROM=q: to the drive letter you want to use\n");
  36.         exit (1);
  37.        }
  38.  
  39.        buf[0] = 'a' + outregs.x.cx;
  40.        buf[1] = ':';
  41.        buf[2] = '\0';
  42.  
  43.        return buf;
  44. }
  45.  
  46. char    *cdrom()
  47.  
  48. {
  49.     static char buf[BUFSIZ];
  50.  
  51.     if (getenv("CDROM") != NULL)
  52.     {
  53.         /* If CDROM found in environment use this */
  54.         strcpy (buf,getenv("CDROM"));
  55.     }
  56.     else
  57.     {
  58.         /* Try to find the cdrom drive letter */
  59.         strcpy (buf,findcdrom());
  60.     }
  61.  
  62.     return buf;
  63. }
  64.  
  65.  
  66.  
  67.  
  68.