fseek, fseeko - reposition a file-position  indicator  in  a


     #include <stdio.h>

     int fseek(FILE *stream, long offset, int whence);

     int fseeko(FILE *stream, off_t offset, int whence);


     The fseek() function sets the  file-position  indicator  for
     the  stream  pointed  to by stream. The fseeko() function is
     identical to fseek() except for the type of offset.

     The new position, measured in bytes from  the  beginning  of
     the  file,  is  obtained  by  adding  offset to the position
     specified by whence, whose values are defined  in  <stdio.h>
     as follows:

           Set position equal to offset bytes.

           Set position to current location plus offset.

           Set position to EOF plus offset.

     If the stream is to be used with wide character input/output
     functions, offset must either be 0 or a value returned by an
     earlier call to ftell(3C) on the same stream and whence must
     be SEEK_SET.

     A successful call to fseek() clears the end-of-file  indica-
     tor  for the stream and undoes any effects of ungetc(3C) and
     ungetwc(3C) on the same stream.  After an fseek() call,  the
     next  operation  on  an update stream may be either input or

     If the most recent operation, other  than  ftell(3C),  on  a
     given  stream is fflush(3C), the file offset in the underly-
     ing open file description will be adjusted  to  reflect  the
     location specified by fseek().

     The fseek() function allows the file-position  indicator  to
     be  set beyond the end of existing data in the file. If data
     is later written at this point, subsequent reads of data  in
     the  gap  will  return  bytes with the value 0 until data is
     actually written into the gap.

     The value of the file offset returned by fseek() on  devices
     which are incapable of seeking is undefined.

     If the stream is writable and buffered  data  had  not  been
     written  to  the  underlying  file,  fseek()  will cause the
     unwritten data to be  written  to  the  file  and  mark  the
     st_ctime and st_mtime fields of the file for update.


     The fseek() and fseeko() functions return 0 on success; oth-
     erwise,  they  returned  -1  and  set  errno to indicate the


     The fseek() and fseeko() functions will fail if, either  the
     stream  is  unbuffered  or  the stream's buffer needed to be
     flushed, and the call  to  fseek()  or  fseeko()  causes  an
     underlying lseek(2) or write(2) to be invoked:

           The O_NONBLOCK flag is set for the file descriptor and
           the process would be delayed in the write operation.

     EBADF The file descriptor underlying the stream file is  not
           open  for  writing or the stream's buffer needed to be
           flushed and the file is not open.

     EFBIG An attempt was made to write a file that  exceeds  the
           maximum file size or the process's file size limit, or
           the file is a regular file and an attempt was made  to
           write  at or beyond the offset maximum associated with
           the corresponding stream.

     EINTR The write operation was terminated due to the  receipt
           of a signal, and no data was transferred.

           The whence argument is invalid.  The  resulting  file-
           position indicator would be set to a negative value.

     EIO   A physical I/O error has occurred; or the process is a
           member  of  a  background  process group attempting to
           perform a write(2) operation to its controlling termi-
           nal,  TOSTOP  is  set, the process is neither ignoring
           nor blocking SIGTTOU, and the  process  group  of  the
           process is orphaned.

           There was no free space remaining on the  device  con-
           taining the file.

     EPIPE The file descriptor underlying  stream  is  associated
           with a pipe or FIFO.

     EPIPE An attempt was made to write to a pipe or FIFO that is
           not  open for reading by any process. A SIGPIPE signal
           will also be sent to the process.

     ENXIO A request was made of a non-existent  device,  or  the
           request was outside the capabilities of the device.

     The fseek() function will fail if:

           The resulting file offset would be a value which  can-
           not  be  represented  correctly  in  an object of type

     The fseeko() function will fail if:

           The resulting file offset would be a value which  can-
           not  be  represented  correctly  in  an object of type


     Although on the UNIX system an offset returned by ftell() or
     ftello()  (see  ftell(3C))  is  measured in bytes, and it is
     permissible to seek to positions relative  to  that  offset,
     portability  to  non-UNIX systems requires that an offset be
     used by fseek() directly.  Arithmetic may  not  meaningfully
     be  performed  on  such  an offset, which is not necessarily
     measured in bytes.

     The fseeko() function has a transitional interface  for  64-
     bit file offsets.  See lf64(5).

     When a UFS file system is mounted with logging enabled, file
     system  transactions  that  free blocks from files might not
     actually add those freed blocks to the  file  system's  free
     list  until  some  unspecified  time  in  the  future.  This
     behavior improves file system performance but does not  con-
     form  to the POSIX, Single UNIX Specification, SPARC Confor-
     mance Definition, System  V  Application  Binary  Interface,
     System  V Interface Definition, and X/Open Portability Guide
     Standards, which  require  that  freed  space  be  available
     immediately.  To enable standards conformance regarding file
     deletions or to address the problem of  not  being  able  to
     grow  files  on a relatively full UFS file system even after
     files  have  been  deleted,   disable   UFS   logging   (see


     See attributes(5) for descriptions of the  following  attri-

    |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
    | MT-Level                    | MT-Safe                     |


     mount_ufs(1M),   getrlimit(2),    ulimit(2),    fopen(3UCB),
     ftell(3C),   rewind(3C),   ungetc(3C),  ungetwc(3C),  attri-
     butes(5), lf64(5)

Man(1) output converted with man2html