Next: , Previous: Closing, Up: Input and Output


27.5 Random Access

— Scheme Procedure: seek object offset whence
— C Function: scm_seek (object, offset, whence)

Set the current position of fd/port to the integer offset, which is interpreted according to the value of whence.

One of the following variables should be supplied for whence:

— Variable: SEEK_SET

Seek from the beginning of the file.

— Variable: SEEK_CUR

Seek from the current position.

— Variable: SEEK_END

Seek from the end of the file.

If fd/port is a file descriptor, the underlying system call is lseek. port may be a string port.

The value returned is the new position in the file. This means that the current position of a port can be obtained using:

          (seek port 0 SEEK_CUR)
— Scheme Procedure: ftell object
— C Function: scm_ftell (object)

Return an integer representing the current position of fd/port, measured from the beginning. Equivalent to:

          (seek port 0 SEEK_CUR)

— Scheme Procedure: truncate-file object [length]
— C Function: scm_truncate_file (object, length) |1 |1 |0

Truncate the object referred to by obj to at most size bytes. obj can be a string containing a file name or an integer file descriptor or a port. size may be omitted if obj is not a file name, in which case the truncation occurs at the current port position.

The return value is unspecified.