Share via


_tell, _telli64

取得檔案指標的位置。

語法

long _tell(
   int handle
);
__int64 _telli64(
   int handle
);

參數

handle
參考已開啟檔案的檔案描述項。

傳回值

檔案指標的目前位置。 在無法搜尋的裝置上,傳回的值為未定義。

-1L 的傳回值表示錯誤。 如果 handle 是不正確檔案描述元,則會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續執行,這些函式會將 errno 設定為 EBADF 並傳回 -1L。

如需傳回碼的詳細資訊,請參閱 errno_doserrno_sys_errlist_sys_nerr

備註

_tell 函式會取得與 handle 引數相關之檔案指標 (若有的話) 的目前位置。 位置是以從檔案開頭的位元組數目來表示。 對於 _telli64 函式,這個值會以 64 位元整數表示。

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
_tell, _telli64 <io.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_tell.c
// This program uses _tell to tell the
// file pointer position after a file read.
//

#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <share.h>
#include <string.h>

int main( void )
{
   int  fh;
   char buffer[500];

   if ( _sopen_s( &fh, "crt_tell.txt", _O_RDONLY, _SH_DENYNO, 0) )
   {
      char buff[50];
      _strerror_s( buff, sizeof(buff), NULL );
      printf( buff );
      exit( -1 );
   }

   if( _read( fh, buffer, 500 ) > 0 )
      printf( "Current file position is: %d\n", _tell( fh ) );
   _close( fh );
}

輸入︰crt_tell.txt

Line one.
Line two.

輸出

Current file position is: 20

另請參閱

低階 I/O
ftell, _ftelli64
_lseek, _lseeki64