


LSEEK(2V)                 SYSTEM CALLS                  LSEEK(2V)



NAME
     lseek, tell - move read/write pointer

SYNOPSIS
     #include <sys/types.h>
     #include <unistd.h>

     off_t lseek(fd, offset, whence)
     int fd;
     off_t offset;
     int whence;

     long tell(fd)
     int fd;

DESCRIPTION
     lseek() sets the seek pointer associated with the open  file
     or  device referred to by the descriptor _f_d according to the
     value supplied for _w_h_e_n_c_e.  _w_h_e_n_c_e must be one of  the  fol-
     lowing constants defined in <unistd.h>:

               SEEK_SET
               SEEK_CUR
               SEEK_END

     If _w_h_e_n_c_e is SEEK_SET, the seek pointer  is  set  to  _o_f_f_s_e_t
     bytes.   If  _w_h_e_n_c_e  is SEEK_CUR, the seek pointer is set to
     its current location plus _o_f_f_s_e_t.  If  _w_h_e_n_c_e  is  SEEK_END,
     the seek pointer is set to the size of the file plus _o_f_f_s_e_t.

     Some devices are incapable of seeking.   The  value  of  the
     seek pointer associated with such a device is undefined.

     The obsolete function tell(fd) is  equivalent  to  lseek(fd,
     0L, SEEK_CUR).

RETURN VALUES
     On success, lseek() returns the  seek  pointer  location  as
     measured  in  bytes  from  the  beginning  of  the file.  On
     failure, it returns -1 and sets errno to indicate the error.

ERRORS
     lseek() will fail and the seek pointer will remain unchanged
     if:

     EBADF          _f_d is not an open file descriptor.

     EINVAL         _w_h_e_n_c_e is not a proper value.

                    The seek operation would result in an illegal
                    file  offset value for the file (for example,
                    a negative file offset for a file other  than



Sun Release 4.1   Last change: 21 January 1990                  1






LSEEK(2V)                 SYSTEM CALLS                  LSEEK(2V)



                    a character special file).

     ESPIPE         _f_d is associated with a pipe or a socket.

SEE ALSO
     dup(2V), open(2V)

NOTES
     Seeking far beyond the end of  a  file,  then  writing,  may
     create a gap or "hole", which occupies no physical space and
     reads as zeros.

     The constants L_SET, L_INCR,  and  L_XTND  are  provided  as
     synonyms  for SEEK_SET, SEEK_CUR, and SEEK_END, respectively
     for backward compatibility but  they  will  disappear  in  a
     future  release.   It  is  unlikely that the underlying con-
     stants 0, 1 and 2 will ever change.






































Sun Release 4.1   Last change: 21 January 1990                  2



