home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / ISFILE.C < prev    next >
C/C++ Source or Header  |  1992-04-26  |  977b  |  47 lines

  1. /*
  2. **  ISFILE.C - determine if a file handle is associated with a file
  3. **
  4. **  public domain by Bob Jarvis
  5. **
  6. **    Returns:    1 - handle is associated with a file
  7. **                0 - handle is associated with a device
  8. **               -1 - error
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13.  
  14. int isfile(int handle)
  15. {
  16.       union REGS regs;
  17.  
  18.       regs.x.ax = 0x4400;
  19.       regs.x.bx = handle;
  20.  
  21.       intdos(®s, ®s);
  22.  
  23.       if(regs.x.cflag == 0)               /* carry flag not set */
  24.       {
  25.             if((regs.x.dx & 0x80) == 0)
  26.                   return 1;
  27.             else  return 0;
  28.       }
  29.       else  return -1;                    /* error - return -1  */
  30. }
  31.  
  32. int isFILE(FILE *fp)
  33. {
  34.       return isfile(fileno(fp));
  35. }
  36.  
  37. #ifdef TEST
  38.  
  39. int main()
  40. {
  41.         if(isFILE(stdout))
  42.                 printf("stdout is associated with a file\n");
  43.         else    printf("stdout is NOT associated with a file\n");
  44. }
  45.  
  46. #endif /* TEST */
  47.