_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