_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