|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
_lseek, _lseeki64
long _lseek( int fd, long offset, int origin ); __int64 _lseeki64( int fd, __int64 offset, int origin );
|
|
|
|---|---|
|
|
|
|
|
|
bibliothèques
// 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 );
}