home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / isatty.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  53 lines

  1. /***
  2. *isatty.c - check if file handle refers to a device
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _isatty() - check if file handle refers to a device
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <msdos.h>
  13. #include <internal.h>
  14. #include <io.h>
  15.  
  16. /***
  17. *int _isatty(handle) - check if handle is a device
  18. *
  19. *Purpose:
  20. *       Checks if the given handle is associated with a character device
  21. *       (terminal, console, printer, serial port)
  22. *
  23. *Entry:
  24. *       int handle - handle of file to be tested
  25. *
  26. *Exit:
  27. *       returns non-0 if handle refers to character device,
  28. *       returns 0 otherwise
  29. *
  30. *Exceptions:
  31. *
  32. *******************************************************************************/
  33.  
  34. int __cdecl _isatty (
  35.         int fh
  36.         )
  37. {
  38.         /* see if file handle is valid, otherwise return FALSE */
  39. #ifndef _MAC
  40.         if ( (unsigned)fh >= (unsigned)_nhandle )
  41. #else  /* _MAC */
  42.         if ((unsigned)fh >= (unsigned)_nfile)
  43. #endif  /* _MAC */
  44.                 return 0;
  45.  
  46.         /* check file handle database to see if device bit set */
  47. #ifndef _MAC
  48.         return (int)(_osfile(fh) & FDEV);
  49. #else  /* _MAC */
  50.         return (int)(_osfile[fh] & FDEV);
  51. #endif  /* _MAC */
  52. }
  53.