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


27.5 Random Access

— Scheme Procedure: seek fd/port offset whence
— C Function: scm_seek (fd/port, 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 fd/port
— C Function: scm_ftell (fd/port)

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 obj [size]
— C Function: scm_truncate_file (obj, size)

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.