다음을 통해 공유


_lseek, _lseeki64

파일 포인터가 지정 된 위치로 이동합니다.

long _lseek(
   int fd,
   long offset,
   int origin 
);
__int64 _lseeki64(
   int fd,
   __int64 offset,
   int origin 
);

매개 변수

  • fd
    파일 설명자를 열린 파일을 참조 합니다.

  • 오프셋
    바이트에서 원본.

  • 시작 위치
    초기 위치입니다.

반환 값

_lseek오프셋을 바이트 단위로 파일의 시작 부분에서 새 위치를 반환합니다._lseeki64오프셋에서 64 비트 정수를 반환합니다.함수는 오류를 표시 하는 –1l을 반환 합니다.잘못 된 파일 설명자 또는 값에는 잘못 된 매개 변수가 전달 된 경우 원본 잘못 되었거나 지정 된 위치입니다 오프셋 는 파일의 시작 전에 잘못 된 매개 변수 처리기를의 설명에 따라 호출 됩니다 매개 변수 유효성 검사.실행을 계속 수 있으면 이러한 함수를 설정 errnoEBADF 및 L-1을 반환 합니다.장치 (터미널, 프린터 등)를 검색을 할 수 없는 것, 반환 값은 정의 되지 않습니다.

이러한 문제 및 기타 오류 코드에 대 한 자세한 내용은 참조 하십시오. _doserrno, errno, _sys_errlist, 및 _sys_nerr.

설명

_lseek 함수 연결 된 파일 포인터 이동 fd 새 위치에 오프셋 바이트 원점.파일에서 다음 작업이 새 위치에서 발생합니다.원본 인수 stdio.h에 정의 된 다음과 같은 상수 중 하나 여야 합니다.

  • SEEK_SET
    파일의 시작 부분입니다.

  • SEEK_CUR
    파일 포인터의 현재 위치입니다.

  • SEEK_END
    파일의 끝입니다.

사용할 수 있습니다 _lseek 파일 또는 파일의 끝 포인터를 아무 곳 이나 위치를 변경 합니다.

요구 사항

루틴

필수 헤더

_lseek

<io.h>

_lseeki64

<io.h>

더 많은 호환성 정보를 참조 하십시오. 호환성 소개에서 합니다.

라이브러리

모든 버전의 C 런타임 라이브러리.

예제

// crt_lseek.c
/* This program first opens a file named lseek.txt.
 * It then uses _lseek to find the beginning of the file,
 * to find the current position in the file, and to find
 * the end of the file.
 */

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

int main( void )
{
   int fh;
   long pos;               /* Position of file pointer */
   char buffer[10];

   _sopen_s( &fh, "crt_lseek.c_input", _O_RDONLY, _SH_DENYNO, 0 );

   /* Seek the beginning of the file: */
   pos = _lseek( fh, 0L, SEEK_SET );
   if( pos == -1L )
      perror( "_lseek to beginning failed" );
   else
      printf( "Position for beginning of file seek = %ld\n", pos );

   /* Move file pointer a little */
    _read( fh, buffer, 10 );

   /* Find current position: */
   pos = _lseek( fh, 0L, SEEK_CUR );
   if( pos == -1L )
      perror( "_lseek to current position failed" );
   else
      printf( "Position for current position seek = %ld\n", pos );

   /* Set the end of the file: */
   pos = _lseek( fh, 0L, SEEK_END );
   if( pos == -1L )
      perror( "_lseek to end failed" );
   else
      printf( "Position for end of file seek = %ld\n", pos );

   _close( fh );
}

입력: crt_lseek.c_input

Line one.
Line two.
Line three.
Line four.
Line five.

Output

Position for beginning of file seek = 0
Position for current position seek = 10
Position for end of file seek = 57

참고 항목

참조

하위 수준 I/O

fseek, _fseeki64

_tell, _telli64