This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/lseek.c

36 lines
787 B
C

long int file_posn;
int handle;
/* get current file position */
file_posn = lseek( handle, 0L, SEEK_CUR );
/* or */
file_posn = tell( handle );
/* return to previous file position */
file_posn = lseek( handle, file_posn, SEEK_SET );
#include <stdio.h>
#include <io.h>
int read_record( int handle,
long rec_numb,
int rec_size,
char *buffer )
{
if( lseek( handle, rec_numb * rec_size, SEEK_SET )
== -1L ) {
return( -1 );
}
return( read( handle, buffer, rec_size ) );
}
.blktext begin
The function in this example assumes records are numbered starting
with zero and that
.arg rec_size
contains the size of a record in the file
(including the carriage-return character in text files).
.blktext end