Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

fcntl(2)

open(2)

read(2)

write(2)



  lseek(2)                            CLIX                            lseek(2)



  NAME

    lseek - Moves read-write file pointer

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <sys/types.h>

    #include <unistd.h>

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

  PARAMETERS

    filedes  Specifies a file descriptor obtained from a successful open(),
             creat(), dup(), or fcntl() function.

    offset   Specifies a value, in bytes, that is used in conjunction with the
             whence parameter to set the file pointer.  A negative value
             causes seeking in the reverse direction.  The resulting file
             position may also be negative.

    whence   Specifies how to interpret the offset in setting the file pointer
             associated with the filedes parameter, as follows:

             SEEK_SET   Sets the file pointer to the value of the offset
                        parameter.

             SEEK_CUR   Sets the file pointer to its current location plus the
                        value of the offset parameter.

             SEEK_END   Sets the file pointer to the size of the file plus the
                        value of the offset parameter.

  DESCRIPTION

    The lseek() function sets the file pointer for the open file specified by
    the filedes parameter.

  EXAMPLES

    1.  To set the file pointer for an open file to location 1000:

        if (lseek(fd, 1000, SEEK_SET) == -1)



  2/94 - Intergraph Corporation                                              1






  lseek(2)                            CLIX                            lseek(2)



                perror("Lseek failed");


    2.  To set the file pointer at the end of a file:

        if (lseek(fd, 0, SEEK_END) == -1)
                perror("Lseek failed");


  RETURN VALUES

    Upon successful completion, the resulting pointer location, measured in
    bytes from the beginning of the file, is returned.  If the lseek()
    function fails, a value of -1 is returned and the global variable errno is
    set to indicate the error.

  ERRORS

    The lseek() function fails and the file pointer remains unchanged if any
    of the following is true:

    [EBADF]    The filedes parameter is not an open file descriptor.

    [ESPIPE]   The filedes parameter is associated with a pipe or fifo.

    [EINVAL]   The whence parameter is not valid; or fildes is not a remote
               file descriptor, and the resulting file pointer would be
               negative.

  RELATED INFORMATION

    Functions: creat(2), dup(2), fcntl(2), open(2), read(2), write(2)






















  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026