home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / DRCURDIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.9 KB  |  66 lines

  1. /**
  2. *
  3. * Name        drcurdir -- Return the current directory path on a given
  4. *                disk drive.
  5. *
  6. * Synopsis    ercode = drcurdir(drive,pdir);
  7. *
  8. *        int  ercode      DOS function return code
  9. *        int  drive      Disk drive (0 = default, 1 = A:, etc.)
  10. *        char *pdir      Directory path of current directory
  11. *
  12. * Description    This function returns the full path name (starting from
  13. *        the root directory) of the current directory for the
  14. *        specified drive.  The returned path name begins with the
  15. *        drive specification and a backslash character ('\\').
  16. *
  17. *        The calling function must allocate sufficient space for
  18. *        the returned full path name.  Because the path can be 64
  19. *        characters (including the trailing null byte), at least
  20. *        MAX_FLEN bytes should be allocated by the calling
  21. *        function for pdir.  (MAX_FLEN is defined in BFILE.H.)
  22. *
  23. * Returns    ercode          DOS function error code
  24. *        *pdir          The full path name of the current directory
  25. *
  26. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  27. *
  28. **/
  29.  
  30. #include <string.h>
  31.  
  32. #include <bdirect.h>
  33. #include <butility.h>
  34.  
  35. int drcurdir(drive,pdir)
  36. int  drive;
  37. char *pdir;
  38. {
  39.     DOSREG dos_reg;
  40.     int    ercode,cur_drive;
  41.     char   path[65];
  42.     ADS    path_ads;
  43.  
  44.     dos_reg.ax = 0x4700;          /* DOS function 0x47 returns    */
  45.     dos_reg.dx = (unsigned)drive;     /* path (without drive          */
  46.     utabsptr(path,&path_ads);          /* specifier)              */
  47.     dos_reg.ds = path_ads.s;
  48.     dos_reg.si = path_ads.r;
  49.  
  50.     ercode     = dos(&dos_reg);
  51.  
  52.     if (ercode == 0)
  53.     {                      /* Add the drive specifier.     */
  54.     if (drive == 0)
  55.        cur_drive = drretdrv();    /* Default drive. Which drive?  */
  56.     else
  57.        cur_drive = drive - 1;
  58.     *pdir    = (char)(cur_drive + 'A');/* First char is drive letter*/
  59.     pdir[1] = '\0';                  /* Now set to concatenate    */
  60.     strcat(pdir,":\\");
  61.     strcat(pdir,path);
  62.     }
  63.  
  64.     return(ercode);
  65. }
  66.