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

  1. /* LASTDRV6.C */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <dos.h>
  6.  
  7. #ifdef __TURBOC__
  8. #define ASM asm
  9. #elif defined(_MSC_VER) && (_MSC_VER >= 600)
  10. #define ASM _asm
  11. #else
  12. #error Requires inline assembler
  13. #endif      
  14.  
  15. unsigned _dos_lastdrive(void)
  16. {
  17.     char far *doslist;
  18.     
  19.     if (_osmajor < 2)
  20.         return 0;
  21.  
  22.     ASM mov ah, 52h
  23.     ASM int 21h
  24.     ASM mov doslist+2, es
  25.     ASM mov doslist, bx
  26.  
  27.     return doslist[(_osmajor == 3 && _osminor == 0) ? 0x1B :
  28.                    (_osmajor == 2) ?                  0x10 :
  29.                    /* otherwise */                    0x21];
  30. }
  31.  
  32. main()
  33. {
  34.     unsigned lastdrive = _dos_lastdrive();
  35.     if (lastdrive == 0xFF)
  36.         return 0;
  37.     fputs("LASTDRIVE=", stdout);
  38.     putchar('A' - 1 + lastdrive);
  39.     putchar('\n');
  40.     return lastdrive;
  41. }
  42.