/* LASTDRV6.C */

#include <stdlib.h>
#include <stdio.h>
#include <dos.h>

#ifdef __TURBOC__
#define ASM asm
#elif defined(_MSC_VER) && (_MSC_VER >= 600)
#define ASM _asm
#else
#error Requires inline assembler
#endif      

unsigned _dos_lastdrive(void)
{
    char far *doslist;
    
    if (_osmajor < 2)
        return 0;

    ASM mov ah, 52h
    ASM int 21h
    ASM mov doslist+2, es
    ASM mov doslist, bx

    return doslist[(_osmajor == 3 && _osminor == 0) ? 0x1B :
                   (_osmajor == 2) ?                  0x10 :
                   /* otherwise */                    0x21];
}

main()
{
    unsigned lastdrive = _dos_lastdrive();
    if (lastdrive == 0xFF)
        return 0;
    fputs("LASTDRIVE=", stdout);
    putchar('A' - 1 + lastdrive);
    putchar('\n');
    return lastdrive;
}
