_isatty
判斷檔案描述元是否與字元裝置相關聯。
語法
int _isatty( int fd );
參數
fd
參照至需要測試之裝置的檔案描述元。
傳回值
如果描述元與字元裝置相關聯,則 _isatty
傳回非零值。 否則,_isatty
會傳回 0。
備註
_isatty
函式會判斷fd
是否與字元裝置 (終端機、主控台、印表機或序列連接埠) 相關聯。
這個函式會驗證 fd
參數。 如果 fd
是不正確的檔案指標,則會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續執行,則函式會傳回 0 並將 errno
設定為 EBADF
。
根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
常式 | 必要的標頭 |
---|---|
_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
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應