home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP2 / LASTDRV4.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-25  |  1.2 KB  |  55 lines

  1. /* LASTDRV4.C -- uses undocumented DOS */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <dos.h>
  6.  
  7. #ifndef MK_FP
  8. #define MK_FP(seg,ofs) \
  9.     ((void far *)(((unsigned long)(seg) << 16) | (ofs)))
  10. #endif
  11.  
  12. main()
  13. {
  14.     union REGS r;
  15.     struct SREGS s;
  16.     char far *doslist;
  17.     unsigned lastdrv_ofs;
  18.     unsigned lastdrv;
  19.  
  20.     /* get offset for LASTDRIVE within DOS List of Lists */
  21.     if (_osmajor < 2)
  22.         return 0;
  23.     else if (_osmajor == 2)
  24.         lastdrv_ofs = 0x10;
  25.     else if (_osmajor == 3 && _osminor == 0)
  26.         lastdrv_ofs = 0x1b;
  27.     else
  28.         lastdrv_ofs = 0x21;
  29.  
  30.     /* Get DOS Lists of Lists */
  31.     r.h.ah = 0x52;
  32.     segread(&s);
  33.     s.es = r.x.bx = 0;
  34.     int86x(0x21, &r, &r, &s);
  35.     /* make sure Function 52h is supported */
  36.     if (! s.es && ! r.x.bx)
  37.         return 0;
  38.     doslist = MK_FP(s.es, r.x.bx);
  39.  
  40.     /* Get LASTDRIVE number */
  41.     lastdrv = doslist[lastdrv_ofs];
  42.  
  43.     /* OS/2 DOS compatibility box sets LASTDRIVE to FFh */
  44.     if (lastdrv == 0xFF)
  45.         return 0;
  46.  
  47.     /* Print LASTDRIVE letter */
  48.     fputs("LASTDRIVE=", stdout);
  49.     putchar('A' - 1 + lastdrv);
  50.     putchar('\n');
  51.  
  52.     /* return LASTDRIVE number to DOS */
  53.     return lastdrv;
  54. }
  55.