_fileno

取得與資料流相關的檔案描述項。

int _fileno( 
   FILE *stream 
);

參數

  • stream
    指標FILE結構。

傳回值

_fileno傳回檔案描述項。沒有任何錯誤傳回。結果是未定義的如果stream不會指定已開啟的檔案。如果資料流NULL,_fileno中所述,將不正確的參數處理常式中,會叫用參數驗證。如果要繼續,這個函式傳回-1 和集合允許執行errno到EINVAL。

如需有關這些及其他錯誤碼的詳細資訊,請參閱 _doserrno、 errno、 _sys_errlist,以及 _sys_nerr

注意事項注意事項

如果stdout或stderr都沒有關聯的輸出資料流 (比方說,在 Windows 應用程式沒有主控台視窗中),傳回的檔案描述項為-2。在先前的版本中,傳回的檔案描述項是-1。這項變更會讓應用程式從錯誤中區別出來這種情況。

備註

_fileno常式會傳回目前與相關聯的檔案描述項stream。這個常式會執行,同時做為函式和巨集。選擇其中一個實作的相關資訊,請參閱選擇之間函式和巨集

需求

Function

所需的標頭

_fileno

<stdio.h>

如需相容性資訊,請參閱相容性在簡介中。

範例

// crt_fileno.c
// This program uses _fileno to obtain
// the file descriptor for some standard C streams.
//

#include <stdio.h>

int main( void )
{
   printf( "The file descriptor for stdin is %d\n", _fileno( stdin ) );
   printf( "The file descriptor for stdout is %d\n", _fileno( stdout ) );
   printf( "The file descriptor for stderr is %d\n", _fileno( stderr ) );
}
  

.NET Framework 對等用法

System::IO::FileStream::Handle

請參閱

參考

資料流 I/O

_fdopen _wfdopen

_filelength _filelengthi64

fopen _wfopen

freopen _wfreopen