Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: Input and Output   [Contents][Index]


6.14.7 Random Access

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

Sets the current position of fd_port to the integer offset. For a file port, offset is expressed as a number of bytes; for other types of ports, such as string ports, offset is an abstract representation of the position within the port’s data, not necessarily expressed as a number of bytes. offset 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 fd_port. 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 file [length]
C Function: scm_truncate_file (file, length)

Truncate file to length bytes. file can be a filename string, a port object, or an integer file descriptor. The return value is unspecified.

For a port or file descriptor length can be omitted, in which case the file is truncated at the current position (per ftell above).

On most systems a file can be extended by giving a length greater than the current size, but this is not mandatory in the POSIX standard.


Next: , Previous: , Up: Input and Output   [Contents][Index]