Seek

Seek allows you to move the read pointer on a file opened by Openi or Openio.
When a null value is sent, it also allows you to flush the write operation performed on a file opened by Openo or Openio.

Syntax

 Seek POSITION MOVE_EXPRSeek MOVE_EXPRSeek POSITION MOVE_EXPR Using [CLASS]Seek MOVE_EXPR Using [CLASS]

Examples

 # Let's open a file and read 10 bytes every 20 bytesSChar BUFFERS(10)(MAXLINES)Openi "MYFILE"fstat = 0 : I = 0RepeatGetseq 1, BUFFERS(I) : I += 1Seek 10Until fstat <> 0 or I >= MAXLINESOpeni# Let's rewrite the 50 last bytes of a fileTinyint BUFFER(50)Openio "MYFILE"Seek Last - 50Getseq 50, BUFFER# .. BUFFER is modifiedSeek Last - 50Putseq 50, BUFFEROpenio# When 2 files are opened:# Let's rewrite the 50 last bytes of the second file with the first 50 bytes of the first fileTinyint BUFFER(50)Openi "MYFILE1" Using [YYY]Openio "MYFILE2" Using [ZZZ]Getseq 50, BUFFER Using [YYY]Seek Last - 50 Using [ZZZ]Putseq 50, BUFFER Using [ZZZ]Openio Using [ZZZ]Openi Using [YYY]# Write 1 byte with "flush" on a file opened without abbreviationPutseq 1, MY_BYTESeek 0

Description

Seek allows you to move the read or read/write pointer when a file is opened by Openi or Openio. The move can be done relatively at:
* The beginning of the file.
* The current position.
* The end of the file.

On some special files (devices), you may not perform a Seek operation and will therefore receive an error.

The Seek 0 syntax flushes the write buffer when the file has been opened by Openo or Openio. It is important, because the write operation is buffered. This syntax can be used on any abbreviation linked to a sequential file (on a file opened by Openi, nothing will happen).

Comments

The function adxseek(0) or adxseek("CLASS") (for a file opened with the [CLASS] abbreviation) allows you to know the current position on the file (in bytes) relatively to the beginning. If no file has been opened, a -1 value is returned.

This function is updated even if you are unable to perform a Seek on the file because it is a special file. In this case, it counts the number of bytes that have been written since the opening of the file.

Associated errors

Error codeDescription
10Non numeric value for MOVE_EXPR.
24No file opened in read or read/write mode.
50Non integer value for MOVE_EXPR.
57Unable to perform a Seek operation on this file.

See also

Openi, Openo, Openio, Getseq, Rdseq, Putseq, Wrseq, adxifs, adxirs, adxium, adxmso.