home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 05oslib / dos / drvpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  867 b   |  38 lines

  1. /*
  2.  *    drvpath -- convert a drive name to a full pathname
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <local\doslib.h>
  10.  
  11. char *
  12. drvpath(path)
  13. char path[];    /* path string */
  14.         /* must be large enough to hold a full DOS path + NUL */
  15. {
  16.     union REGS inregs, outregs;
  17.     static int drive(char);
  18.  
  19.     /* patch root directory onto drive name */
  20.     strcat(path, "\\");
  21.  
  22.     /* set current directory path for drive from DOS */
  23.     inregs.h.ah = GET_CUR_DIR;
  24.     inregs.h.dl = drive(path[0]);        /* convert to drive number */
  25.     inregs.x.si = (unsigned)&path[3];    /* start of return string */
  26.     intdos(&inregs, &outregs);
  27.  
  28.     return (outregs.x.cflag ? (char *)NULL : path); 
  29. }
  30.  
  31. static int
  32. drive(dltr)
  33. char dltr;    /* drive letter */
  34. {
  35.     /* 'A' (or 'a') => 1, 'B' (or 'b') => 2, etc. */
  36.     return (tolower(dltr) - 'a' + 1);
  37. }
  38.