home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_01 / 3n01058a < prev    next >
Text File  |  1991-10-15  |  1KB  |  38 lines

  1. /*
  2.  * redir.c:
  3.  *
  4.  * C version of redir() redirection detection function.
  5.  */
  6.  
  7. #include <dos.h>
  8. #include <stdlib.h>
  9.  
  10. unsigned char redir (void)  /* Test for redirection of standard devices */
  11. {
  12.   unsigned char far *fht_ptr;       /* File Handle Table pointer */
  13.   int i;                              /* loop counter */
  14.   unsigned char ret_val, handle_bit;  /* return value and bit-setter */
  15.   const unsigned char nrml_hndl[5] =
  16.       { 0x01,    /* STDIN default CON: */
  17.         0x01,    /* STDOUT default CON: */
  18.         0x01,    /* STDERR default CON: */
  19.         0x00,    /* AUXIO default AUX: */
  20.         0x02     /* LSTOUT default PRN: */
  21.       };
  22.   
  23.   /* Set fht_ptr at File Handle Table */
  24.   fht_ptr = *(unsigned char far * far *)MK_FP(_psp,0x0034);
  25.  
  26.   ret_val = 0x00;                  /* Assume no redirection */
  27.   handle_bit = 0x01;               /* Set bit 0 of handle_bit */
  28.  
  29.   for (i = 0; i < 5; ++i)          /* There are five defaults */
  30.   {
  31.     if (*(fht_ptr++) != nrml_hndl[i])  /* ith value in Table == default? */
  32.       ret_val |= handle_bit;       /* If not, set bit (2 ** i) in ret_val */
  33.     handle_bit <<= 1;              /* Shift to set next bit in handle_bit */
  34.   }
  35.  
  36.   return(ret_val);
  37. }
  38.