_isatty

确定文件描述符与字符设备是否相关。

int _isatty( 
int fd  
);

参数

  • fd
    引用要测试的计算机上的文件描述符。

返回值

如果描述符与字符设备相关,_isatty 返回一个非零值。 否则,_isatty 返回0 。

备注

_isatty 函数确定 fd 是否与字符设备 (终端、控件台、打印机或串行端口)相关。

此函数验证 fd 参数。 如果 fd 是一个坏的文件指针,无效参数处理程序将被调用,如参数验证所述。 如果允许执行继续,则该函数返回 0 并将 errno 设置为 EBADF

要求

例程

必需的标头

_isatty

<io.h>

有关更多兼容性信息,请参见兼容性

C 运行时库的所有版本。

示例

// crt_isatty.c
/* This program checks to see whether
 * stdout has been redirected to a file.
 */

#include <stdio.h>
#include <io.h>

int main( void )
{
   if( _isatty( _fileno( stdout ) ) )
      printf( "stdout has not been redirected to a file\n" );
   else
      printf( "stdout has been redirected to a file\n");
}

示例输出

stdout has not been redirected to a file

请参见

参考

文件处理