[ ECLiPSe Stream I/O built-in.|Group Index| Full Index]

seek(+Stream, +Offset)

The pointer in stream Stream is offset Offset from the start of the file.

+Stream
Integer (stream number) or Atom (reserved or user-defined symbolic stream name).
+Offset
Integer or the atom end_of_file.

Description

Moves the file pointer to offset Offset from the start of the file opened. It is an error if Stream is not a stream or if Offset is not an integer or the atom end_of_file.

seek/2 seeks to the end of the file when Offset is instantiated to end_of_file.

seek/2 has no effect on the null stream, it always succeeds.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Either Stream or Offset is uninstantiated.
(5) Type error
Offset is instantiated, but not to an integer or the atom end_of_file.
(5) Type error
Stream is instantiated, but not to an atom or an integer.
(6) Range error
Offset is a negative integer or greater than the file length.
(192)
Stream is in an illegal stream mode.
(193)
Stream is an illegal stream specification.

Examples


Success:
      seek( 0,null). % does not modify, only succeeds

      [eclipse]: open(file1,update,s), write(hello,s),
      > seek(3,s), read(T,s), close(s).
      T = lo
      yes.

Error:
      seek( Offset,7).      (Error 4).
      seek("7", 2).         (Error 5).
      seek(7, -1).          (Error 6).
      seek( 0,input).       (Error 192).
      seek(-1, 0).          (Error 193). % does not exist


See Also

at / 2, at_eof / 1