_isatty
判斷檔案描述項是否與字元裝置。
int _isatty( int fd );
參數
- fd
表示裝置的檔案描述項要測試。
傳回值
如果描述元與字元裝置,則**_isatty** 會傳回非零的值。否則, _isatty 會傳回 0。
備註
_isatty 函式會判斷 fd 是否與字元裝置 (終端機、主控台、印表機、序列埠)。
這個函式驗證 fd 參數。如果 fd 是錯誤的檔案指標,無效的參數叫用處理常式,如 參數驗證中所述。如果執行允許繼續執行,函式會傳回 0 並將 errno 設定為 EBADF。
需求
程序 |
必要的標頭檔 |
---|---|
_isatty |
<io.h> |
如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility) 。
程式庫
所有的 C 執行階段程式庫 (C run-time libraries) 版本。
範例
// 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