Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

  1. /***
  2. *isatty.c - check if file handle refers to a device
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _isatty() - check if file handle refers to a device
  8. *
  9. *Revision History:
  10. * 06-08-89 PHG Module created
  11. * 03-12-90 GJF Made calling type _CALLTYPE1, added #include
  12. * <cruntime.h> and fixed the copyright. Also, cleaned
  13. * up the formatting a bit.
  14. * 08-14-90 SBM Compiles cleanly with -W3, minor optimization
  15. * 09-28-90 GJF New-style function declarator.
  16. * 12-04-90 GJF Appended Win32 version onto the source with #ifdef-s.
  17. * It's not worth it to try to merge the versions more
  18. * closely.
  19. * 12-06-90 SRW Changed to use _osfile and _osfhnd instead of _osfinfo
  20. * 01-16-91 GJF ANSI naming.
  21. * 02-13-92 GJF Replaced _nfile by _nhandle for Win32.
  22. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  23. * 01-04-95 GJF _WIN32_ -> _WIN32
  24. * 06-06-95 GJF Replaced _osfile[] with _osfile() (macro referencing
  25. * field in ioinfo struct).
  26. * 07-08-96 GJF Replaced defined(_WIN32) with !defined(_MAC). Also,
  27. * detab-ed.
  28. * 05-17-99 PML Remove all Macintosh support.
  29. *
  30. *******************************************************************************/
  31. #include <cruntime.h>
  32. #include <msdos.h>
  33. #include <internal.h>
  34. #include <io.h>
  35. /***
  36. *int _isatty(handle) - check if handle is a device
  37. *
  38. *Purpose:
  39. * Checks if the given handle is associated with a character device
  40. * (terminal, console, printer, serial port)
  41. *
  42. *Entry:
  43. * int handle - handle of file to be tested
  44. *
  45. *Exit:
  46. * returns non-0 if handle refers to character device,
  47. * returns 0 otherwise
  48. *
  49. *Exceptions:
  50. *
  51. *******************************************************************************/
  52. int __cdecl _isatty (
  53. int fh
  54. )
  55. {
  56. /* see if file handle is valid, otherwise return FALSE */
  57. if ( (unsigned)fh >= (unsigned)_nhandle )
  58. return 0;
  59. /* check file handle database to see if device bit set */
  60. return (int)(_osfile(fh) & FDEV);
  61. }