4.17.2 ISO Input and Output Streams
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Input and output
          • ISO Input and Output Streams
            • open/4
            • open/3
            • open_null_stream/1
            • close/1
            • close/2
            • stream_property/2
            • current_stream/3
            • is_stream/1
            • stream_pair/3
            • set_stream_position/2
            • stream_position_data/3
            • seek/4
            • set_stream/2
            • set_prolog_IO/3
            • set_system_IO/3
    • Packages
Availability:built-in
seek(+Stream, +Offset, +Method, -NewLocation)
Reposition the current point of the given Stream. Method is one of bof, current or eof, indicating positioning relative to the start, current point or end of the underlying object. NewLocation is unified with the new offset, relative to the start of the stream.

Positions are counted inā€˜units'. A unit is 1 byte, except for text files using 2-byte Unicode encoding (2 bytes) or wchar encoding (sizeof(wchar_t)). The latter guarantees comfortable interaction with wide-character text objects. Otherwise, the use of seek/4 on non-binary files (see open/4) is of limited use, especially when using multi-byte text encodings (e.g. UTF-8) or multi-byte newline files (e.g. DOS/Windows). On text files, SWI-Prolog offers reliable backup to an old position using stream_property/2 and set_stream_position/2. Skipping N character codes is achieved calling get_code/2 N times or using copy_stream_data/3, directing the output to a null stream (see open_null_stream/1). If the seek modifies the current location, the line number and character position in the line are set to 0.

If the stream cannot be repositioned, a permission_error is raised. If applying the offset would result in a file position less than zero, a domain_error is raised. Behaviour when seeking to positions beyond the size of the underlying object depend on the object and possibly the operating system. The predicate seek/4 is compatible with Quintus Prolog, though the error conditions and signalling is ISO compliant. See also stream_property/2 and set_stream_position/2.