lseek()                  Reposition File Pointer to Specified Location
 
 #include   <io.h>                       Required for declarations only
 
 long       lseek(handle,offset,origin);
 int        handle                       Open file handle
 long       offset                       Number of bytes from origin
 int        origin                       Reference point of the seek
 
    lseek() moves the file pointer associated with 'handle' to a new
    location.  The location is 'offset' bytes from the 'origin'. 'origin'
    can be one of the following constants:
 
            SEEK_SET     Beginning of file
            SEEK_CUR     Current pointer position
            SEEK_END     End of file
 
    The pointer can be repositioned anywhere in the file.
 
    Returns:    The offset of the pointer's new position, specified in
                bytes from the beginning of the file. On error, lseek()
                returns -1L, and ERRNO is set to one of the following:
 
                    EBADF:      Invalid file handle
                    EINVAL:     Offset is before the beginning of the file
 
      Notes:    lseek() can reposition the pointer beyond the end of the
                file.  Trying to reposition the pointer before the
                beginning of the file will cause an error, however.
 
                On devices incapable of seeking (such as terminals and
                printers), the return value is undefined.
 
                Use tell() to read the current position of the file
                pointer.
 
  -------------------------------- Example ---------------------------------
 
    The following statements open a file, move the file pointer to the
    end of the file, and write at that position.
 
         #include <io.h>
         #include <fnctl.h>
         #include <stdlib.h>
 
         int fhndl;
         char buff[10000];
         long position;
 
         main()
         {
                fhndl = open("invoice.dat",O_RDWR);
                position = lseek(fhndl,0L,SEEK_END);
                if (position != -1)
                   write(fhndl,buff,10);
         }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster