Borland C++ reference

lseek

raw OCR

Moves file pointer.

Defined in header <io.h>

Syntax

#include <io.h>
long lseek(int handle, long offset,intfromwhere);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

Iseek sets the file pointer associated with handle to a new position offset bytes beyond the file location given by fromwhere. It is a good idea to set fromwhere using one of three symbolic constants (defined in io.h) instead of a specific number. The constants are

fromwhereFile location

SEEK_SET (0) File beginning SEEK_CUR (1) Current file pointer position SEEK_END (2) End-of-file

Return value

Iseek returns the offset of the pointer's new position measured in bytes from the file beginning. Iseek returns -IL on error, and the global variable errno is set to one of the following:

EBADFBad file number
EINVALInvalid argument

On devices incapable of seeking (such as terminals and printers), the return value is undefined.

See also

Example

#include <sys\stat.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
   int handle;
   char insg[] = "This is a test";
   char ch;

   /* create a file */
   handle = open( "TEST.$$$", 0_CREAT   0_RDWR, S_IREAD I S_IWRITE)
   /* write some data to the  file */
   write(handle, msg, strlen(msg) );

   /* seek to the begining of  the file */
   lseek(handle, 0L, SEEK_SET) ;
   /* reads chars from the  file until EOF */
   do {
      read(handle, &ch,  1);
      printf("%c", ch) ;
   }
   while (!eof (handle));
   close(handle);

   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `Iseek` read as `lseek`