home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / fileutil / tcggrep2.arj / GETWD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-24  |  1.9 KB  |  89 lines

  1. /*-
  2.  * MSDOS routine for getting the working directory on a specified drive.
  3.  * By Barry Schwartz, 12 August 1990
  4.  */
  5. /* modified for Turbo C Jim Segrave 00:06:21 Sat Nov 24 1990
  6.    added prototypes, the odd cast, defined LARGE_DATA using
  7.    the Turbo C internal constants. It compiles without warnings now
  8. */
  9.  
  10. #include <stddef.h>
  11. #include <dos.h>
  12. #include "msd_dir.h"
  13.  
  14. #undef LARGE_DATA
  15. #ifdef __TURBOC__
  16. #  if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
  17. #    define LARGE_DATA
  18. #  endif
  19. #else
  20. #  if defined(M_I86CM) || defined(M_I86LM) || defined(M_I86HM)
  21. #    define LARGE_DATA
  22. #  endif
  23. #endif
  24.  
  25. static union REGS inregs, outregs;
  26. #ifdef LARGE_DATA
  27. static struct SREGS segregs;
  28. #endif
  29.  
  30.  
  31.  
  32. /*
  33.  * get_working_directory(buf, drive) Returns buf, or NULL if the drive
  34.  * specification is invalid. 
  35.  */
  36.  
  37. char           *
  38. get_working_directory(buf, drive)
  39. char           *buf;        /* Pointer to a buffer of sufficient size
  40.                  * (_MAX_DIR) */
  41. int             drive;        /* Drive number (0=default, 1=`A:',
  42.                  * 2=`B:', etc.) */
  43. {
  44.     inregs.h.ah = 0x47;        /* DOS interrupt number */
  45.     inregs.h.dl = drive;
  46. #ifdef LARGE_DATA
  47.     inregs.x.si = FP_OFF(buf);    /* SI points to buf within the segment */
  48.     segregs.ds = FP_SEG(buf);    /* DS points to the segment */
  49.     intdosx(&inregs, &outregs, &segregs);
  50. #else
  51.     inregs.x.si = (unsigned int) buf;
  52.     intdos(&inregs, &outregs);
  53. #endif
  54.     if (outregs.x.cflag)
  55.     return NULL;
  56.     return buf;
  57. }
  58.  
  59.  
  60.  
  61. #ifdef TEST
  62.  
  63.  
  64. #include <stdlib.h>
  65.  
  66.  
  67. char            working_dir[_MAX_PATH];
  68.  
  69.  
  70. main()
  71. {
  72.     int             drive;
  73.     char           *result;
  74.  
  75.     for (drive = 0; drive != 10; ++drive)
  76.     {
  77.     result = get_working_directory(working_dir, drive);
  78.     if (result)
  79.         printf("drive = %2d        working directory = %s\n",
  80.            drive, result);
  81.     else
  82.         printf("drive = %2d        invalid drive specification\n",
  83.            drive);
  84.     }
  85. }
  86.  
  87.  
  88. #endif
  89.