Node:Random Access, Next:, Previous:Closing, Up:Input and Output

27.5 Random Access

seek fd_port offset whence Scheme Procedure
scm_seek (fd_port, offset, whence) C Function
Sets 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:

SEEK_SET Variable
Seek from the beginning of the file.

SEEK_CUR Variable
Seek from the current position.

SEEK_END Variable
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)

ftell fd_port Scheme Procedure
scm_ftell (fd_port) C Function
Return an integer representing the current position of fd/port, measured from the beginning. Equivalent to:
(seek port 0 SEEK_CUR)

truncate-file object [length] Scheme Procedure
scm_truncate_file (object, length) C Function
Truncates the object referred to by object to at most length bytes. object can be a string containing a file name or an integer file descriptor or a port. length may be omitted if object is not a file name, in which case the truncation occurs at the current port. position. The return value is unspecified.