New in version 6.3.0: See the new features.

Position a sequential file at a stated position

fseek

Seek a sequential file


SYNTAX

fseek file_handle offset origin [err = label] [traps = label]

Positions a sequential file to a specified offset, relative to the start of the file, end of the file or current position (depending on the origin argument). This file position will be used by the next sequential file read or write command.

file_handle

It can be the handle returned by the fopen command (it returns a negative number to differentitate the #channel case) or an integer in the range 1-64 specifying the number of the channel on which the sequential file, socket or pipe (opened by the open # command) is open. It may be a constant, field name or expression.

offset

An integer value defining the position required. Referenced from the file beginning, end or current position (see origin parameter). The built-in function tell() returns the current position of a sequential file starting from the beginning.

The position may be any expression that evaluates to an integer value.

origin

Position used as reference for the offset. It is specified by one of the following possible strings:

“b”

Beginning of file

“c”

Current file “pointer” position

“e”

End of file

[err = label]

Errors return the trappable condition err, which may be trapped by the err = clause or by the general traps = clause. The error number is stored in the system variable sys.Error , and control passes to the line indicated by label. The error numbers are defined by manifest constants in the file errors.h, which is located in the Sculptor include directory. This file may be included in a program by means of an !include declaration. The possible errors are:

No

Manifest constant

Meaning

1

BAD_CHANNEL

file_handle is wrong

13

CHECK_ERRNO

general error, check errno

14

BAD_ARGS

bad/wrong number of arguments

If an error occurs and is not trapped, an error message is displayed and control passes to the active menu, if any. If no menu is active the program exits.

[traps = label]

General purpose trap clause that traps any condition not explicitly trapped, passing control to the line indicated by label. It has the lowest priority, and is only invoked if a trappable condition has not been more explicitly trapped.


NOTES

  • If the handle/channel is already closed the command is ignored.

  • Seeking to a position past the end of the file is not generally recommended, but is allowed. Subsequent behaviour is operating system dependent.


EXAMPLE

To position the file “pointer” to the 256 byte from the start of the file:

!temp fHandle,,i2

fopen fHandle "seqfile" "r"
fseek fHandle 256 "b"

RELATED TOPICS

tell()

fopen

fclose

rewind #

seek #

wind #

Sequential files

Fcmds

Traps